From e7f0148a563b3dc9a08bb7e18efef555658425b8 Mon Sep 17 00:00:00 2001 From: magicwerk Date: Mon, 18 Dec 2023 12:06:42 +0100 Subject: [PATCH] fix-issue-441 (#442) Co-authored-by: Thomas Mauch --- .../testing/junit5/UpdateTestAnnotation.java | 4 - .../testing/junit5/JUnit5MigrationTest.java | 2 +- .../junit5/UpdateTestAnnotationTest.java | 90 ++++--------------- .../JunitMockitoUpgradeIntegrationTest.java | 2 +- 4 files changed, 17 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java index 7a3590018..211e09b0b 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java @@ -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(new MethodMatcher(m), null) - .visitNonNull(m, ctx, getCursor().getParentOrThrow()); - } if (cta.expectedException != null) { m = JavaTemplate.builder("org.junit.jupiter.api.function.Executable o = () -> #{};") .contextSensitive() diff --git a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java index 37dc7e498..4a0e29711 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java @@ -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")); } diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java index 8ed0f9219..61743716f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotationTest.java @@ -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]; }); @@ -95,7 +95,7 @@ public void test() { public class MyTest { @Test - void test() { + public void test() { assertThrows(IllegalArgumentException.class, () -> { throw new IllegalArgumentException("boom"); }); @@ -131,7 +131,7 @@ public void test() { public class MyTest { @Test - void test() { + public void test() { assertThrows(IndexOutOfBoundsException.class, () -> { int arr = new int[]{}[0]; }); @@ -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"); @@ -200,7 +200,7 @@ public void test() { public class MyTest { @Test - void test() { + public void test() { } } """ @@ -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() { } } """ @@ -294,7 +294,7 @@ public class MyTest { @Test @Timeout(500) - void test() { + public void test() { } } """ @@ -338,7 +338,7 @@ public void test() { public class MyTest { @Test - void test() { + public void test() { assertThrows(MyException.class, () -> { throw new MyException("my exception"); }); @@ -375,7 +375,7 @@ public class MyTest { @Test @Timeout(500) - void test() { + public void test() { assertThrows(IllegalArgumentException.class, () -> { throw new IllegalArgumentException("boom"); }); @@ -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 @@ -532,7 +472,7 @@ public void test() { /** @see org.junit.jupiter.api.Test */ public class MyTest { @Test - void test() { + public void test() { } } """ @@ -557,7 +497,7 @@ public void feature1() { public class MyTest { @org.junit.jupiter.api.Test - void feature1() { + public void feature1() { } } """ @@ -587,7 +527,7 @@ void feature2() { public class MyTest { @org.junit.jupiter.api.Test - void feature1() { + public void feature1() { } @Test diff --git a/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java b/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java index 29fa8995e..9c1deef31 100755 --- a/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.java @@ -108,7 +108,7 @@ public void initMocks() { } @Test - void usingAnnotationBasedMock() { + public void usingAnnotationBasedMock() { mockedList.add("one"); mockedList.clear();