'How to replace all `public void` "Test"-methods with just "void" (with SSR and IntelliJ)
I've recently joined a codebase that no one seemed to ever run SonarLint against, and now every test class I open in IntelliJ is highlighted like a Christmas tree - all test methods are public, even though JUnit5 is used.
Tired of removing those public modifiers manually, I decided to implement an SSR template to do that for me. However, I can't seem to make it work with method parameter annotations! (which seem to be rather usual thing with JMockit)
The best I can have thus far is this:
- Open
Edit->Find->Replace structurally - Paste this into
Searchfield:@$MethodAnnotation$ public void $MethodName$(@mockit.Injectable $ParameterType$ $Parameter$) { $statement$; } - Choose file type:
Java - Class Member - Add filter for
MethodAnnotationvariable: Text=org.junit.jupiter.api.Test - Add Min=0 for
statementandParametervariables - Paste this into
Replacefield:
(mind the indentation, otherwise it will be problematic!)@$MethodAnnotation$ void $MethodName$(@Injectable $ParameterType$ $Parameter$) { $statement$; } - Select
Complete matchvalue forSearch target - Find
As you can see, the annotation is hard-coded, which of course limits the applicability of this snippet seriously.
Is this a problem with IntelliJ or rather my bad knowledge of SSR? What would be a proposed solution?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
