Skip to content

Commit

Permalink
fix-issue-441 (#442)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Mauch <[email protected]>
  • Loading branch information
magicwerk and Thomas Mauch authored Dec 18, 2023
1 parent e383281 commit e7f0148
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
ChangeTestAnnotation cta = new ChangeTestAnnotation();
J.MethodDeclaration m = (J.MethodDeclaration) cta.visitNonNull(method, ctx, getCursor().getParentOrThrow());
if (m != method) {
if (Boolean.FALSE.equals(TypeUtils.isOverride(m.getMethodType()))) {
m = (J.MethodDeclaration) new ChangeMethodAccessLevelVisitor<ExecutionContext>(new MethodMatcher(m), null)
.visitNonNull(m, ctx, getCursor().getParentOrThrow());
}
if (cta.expectedException != null) {
m = JavaTemplate.builder("org.junit.jupiter.api.function.Executable o = () -> #{};")
.contextSensitive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void filterShouldRemoveUnusedConfig() {
public class SampleTest {
@SuppressWarnings("ALL")
@Test
void filterShouldRemoveUnusedConfig() {
public void filterShouldRemoveUnusedConfig() {
assertThat(asList("1", "2", "3"),
containsInAnyOrder("3", "2", "1"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void test_printLine() {
public class MyTest {
@Test
void test_printLine() {
public void test_printLine() {
assertDoesNotThrow(() -> {
int arr = new int[]{0}[0];
});
Expand Down Expand Up @@ -95,7 +95,7 @@ public void test() {
public class MyTest {
@Test
void test() {
public void test() {
assertThrows(IllegalArgumentException.class, () -> {
throw new IllegalArgumentException("boom");
});
Expand Down Expand Up @@ -131,7 +131,7 @@ public void test() {
public class MyTest {
@Test
void test() {
public void test() {
assertThrows(IndexOutOfBoundsException.class, () -> {
int arr = new int[]{}[0];
});
Expand Down Expand Up @@ -167,7 +167,7 @@ public void test() {
public class MyTest {
@Test
void test() {
public void test() {
assertThrows(IllegalArgumentException.class, () -> {
String foo = "foo";
throw new IllegalArgumentException("boom");
Expand Down Expand Up @@ -200,7 +200,7 @@ public void test() {
public class MyTest {
@Test
void test() {
public void test() {
}
}
"""
Expand Down Expand Up @@ -253,17 +253,17 @@ public class MyTest {
// some comments
@Issue("some issue")
@Test
void test() {
public void test() {
}
// some comments
@Test
void test1() {
public void test1() {
}
// some comments
@Test
void test2() {
// some comments
public void test2() {
}
}
"""
Expand Down Expand Up @@ -294,7 +294,7 @@ public class MyTest {
@Test
@Timeout(500)
void test() {
public void test() {
}
}
"""
Expand Down Expand Up @@ -338,7 +338,7 @@ public void test() {
public class MyTest {
@Test
void test() {
public void test() {
assertThrows(MyException.class, () -> {
throw new MyException("my exception");
});
Expand Down Expand Up @@ -375,7 +375,7 @@ public class MyTest {
@Test
@Timeout(500)
void test() {
public void test() {
assertThrows(IllegalArgumentException.class, () -> {
throw new IllegalArgumentException("boom");
});
Expand All @@ -386,66 +386,6 @@ void test() {
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/150")
@Test
void protectedToPackageVisibility() {
//language=java
rewriteRun(
java(
"""
import org.junit.Test;
public class MyTest {
@Test
protected void test() {
}
}
""",
"""
import org.junit.jupiter.api.Test;
public class MyTest {
@Test
void test() {
}
}
"""
)
);
}

@SuppressWarnings("JUnitMalformedDeclaration")
@Test
void privateToPackageVisibility() {
//language=java
rewriteRun(
java(
"""
import org.junit.Test;
public class MyTest {
@Test
private void test() {
}
}
""",
"""
import org.junit.jupiter.api.Test;
public class MyTest {
@Test
void test() {
}
}
"""
)
);
}

@Test
void preservesVisibilityOnTestMethodThatIsAnOverride() {
//language=java
Expand Down Expand Up @@ -532,7 +472,7 @@ public void test() {
/** @see org.junit.jupiter.api.Test */
public class MyTest {
@Test
void test() {
public void test() {
}
}
"""
Expand All @@ -557,7 +497,7 @@ public void feature1() {
public class MyTest {
@org.junit.jupiter.api.Test
void feature1() {
public void feature1() {
}
}
"""
Expand Down Expand Up @@ -587,7 +527,7 @@ void feature2() {
public class MyTest {
@org.junit.jupiter.api.Test
void feature1() {
public void feature1() {
}
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void initMocks() {
}
@Test
void usingAnnotationBasedMock() {
public void usingAnnotationBasedMock() {
mockedList.add("one");
mockedList.clear();
Expand Down

0 comments on commit e7f0148

Please sign in to comment.