Skip to content

Commit

Permalink
Simplify TestsShouldNotBePublic
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Aug 20, 2024
1 parent 8e001a9 commit 671fe03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Option;
Expand Down Expand Up @@ -154,9 +153,12 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
return m;
}

if (m.getModifiers().stream().anyMatch(mod -> (mod.getType() == J.Modifier.Type.Public || (orProtected && mod.getType() == J.Modifier.Type.Protected)))
&& Boolean.FALSE.equals(TypeUtils.isOverride(method.getMethodType()))
&& hasJUnit5MethodAnnotation(m)) {
if (m.hasModifier(J.Modifier.Type.Abstract) || TypeUtils.isOverride(method.getMethodType())) {
return m;
}

if ((m.hasModifier(J.Modifier.Type.Public) || (orProtected && m.hasModifier(J.Modifier.Type.Protected))) &&
hasJUnit5MethodAnnotation(m)) {
// remove public modifier
doAfterVisit(new ChangeMethodAccessLevelVisitor<>(new MethodMatcher(method), null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void testMethod() {
@Nested
public class NestedTestClass {
@Test
void anotherTestMethod() {
}
Expand Down Expand Up @@ -198,9 +198,9 @@ void ignoreOverriddenMethod() {
abstract class AbstractTest {
public abstract void testMethod();
}
class BTest extends AbstractTest {
@Test
@Override
public void testMethod() {
Expand Down

0 comments on commit 671fe03

Please sign in to comment.