From f808ed476e5d779f20a13ccc14e66c68da381d33 Mon Sep 17 00:00:00 2001 From: Shivani Sharma Date: Sun, 28 Jul 2024 14:05:43 +1000 Subject: [PATCH 1/6] Add unit tests for JMockit Delegate to mockito migration. Also add one test case for comments for JMockit Expectations proving that comments are not preserved. --- .../jmockit/JMockitDelegateToMockitoTest.java | 375 ++++++++++++++++++ .../JMockitExpectationsToMockitoTest.java | 69 ++++ 2 files changed, 444 insertions(+) create mode 100644 src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java new file mode 100644 index 000000000..291e0fa80 --- /dev/null +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java @@ -0,0 +1,375 @@ +/* + * Copyright 2023 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.testing.jmockit; + +import org.junit.jupiter.api.Test; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; +import org.openrewrite.test.TypeValidation; + +import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.java.testing.jmockit.JMockitTestUtils.setDefaultParserSettings; + +/** + * At the moment, JMockit Delegates are not migrated to mockito. What I'm seeing is that they are being trashed + * with the template being printed out. These tests were written to try to replicate this issue, however I was unable to. + * They may help anyone adding feature for Delegate migration. + */ +class JMockitDelegateToMockitoTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + setDefaultParserSettings(spec); + } + + @Test + void whenNoArgsVoidMethod() { + //language=java + rewriteRun( + spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), + java( + """ + import mockit.Expectations; + import mockit.Delegate; + import mockit.Mocked; + import mockit.integration.junit5.JMockitExtension; + import org.junit.jupiter.api.extension.ExtendWith; + + @ExtendWith(JMockitExtension.class) + class MyTest { + @Mocked + Object myObject; + + void test() { + new Expectations() {{ + myObject.wait(); + result = new Delegate() { + public void wait() { + System.out.println("bla"); + } + }; + }}; + myObject.wait(); + } + } + """, + """ + import mockit.Delegate; + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mock; + import org.mockito.junit.jupiter.MockitoExtension; + + import static org.mockito.Mockito.when; + + @ExtendWith(MockitoExtension.class) + class MyTest { + @Mock + Object myObject; + + void test() { + when(myObject.wait()).thenReturn(new Delegate() { + public void wait() { + System.out.println("bla"); + } + }); + myObject.wait(); + } + } + """ + ) + ); + } + + @Test + void whenHasArgsVoidMethod() { + //language=java + rewriteRun( + spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), + java( + """ + import mockit.Expectations; + import mockit.Delegate; + import mockit.Mocked; + import mockit.integration.junit5.JMockitExtension; + import org.junit.jupiter.api.extension.ExtendWith; + + import static org.junit.jupiter.api.Assertions.assertEquals; + + @ExtendWith(JMockitExtension.class) + class MyTest { + @Mocked + Object myObject; + + void test() { + new Expectations() {{ + myObject.wait(anyLong); + result = new Delegate() { + void wait(long timeoutMs) { + System.out.println("bla"); + System.out.println("bla"); + } + }; + }}; + myObject.wait(); + } + } + """, + """ + import mockit.Delegate; + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mock; + import org.mockito.junit.jupiter.MockitoExtension; + + import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.mockito.Mockito.anyLong; + import static org.mockito.Mockito.when; + + @ExtendWith(MockitoExtension.class) + class MyTest { + @Mock + Object myObject; + + void test() { + when(myObject.wait(anyLong())).thenReturn(new Delegate() { + void wait(long timeoutMs) { + System.out.println("bla"); + System.out.println("bla"); + } + }); + myObject.wait(); + } + } + """ + ) + ); + } + + @Test + void whenNoArgsNonVoidMethod() { + //language=java + rewriteRun( + spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), + java( + """ + import mockit.Expectations; + import mockit.Delegate; + import mockit.Mocked; + import mockit.integration.junit5.JMockitExtension; + import org.junit.jupiter.api.extension.ExtendWith; + + import static org.junit.jupiter.api.Assertions.assertEquals; + + @ExtendWith(JMockitExtension.class) + class MyTest { + @Mocked + Object myObject; + + void test() { + new Expectations() {{ + myObject.toString(); + result = new Delegate() { + String toString() { + String a = "bla"; + return a + "foo"; + } + }; + }}; + myObject.toString(); + } + } + """, + """ + import mockit.Delegate; + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mock; + import org.mockito.junit.jupiter.MockitoExtension; + + import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.mockito.Mockito.when; + + @ExtendWith(MockitoExtension.class) + class MyTest { + @Mock + Object myObject; + + void test() { + when(myObject.toString()).thenReturn(new Delegate() { + String toString() { + String a = "bla"; + return a + "foo"; + } + }); + myObject.toString(); + } + } + """ + ) + ); + } + + @Test + void whenMultipleStatementsWithAnnotation() { + //language=java + rewriteRun( + spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), + java( + """ + import mockit.Expectations; + import mockit.Delegate; + import mockit.Mocked; + import mockit.integration.junit5.JMockitExtension; + import org.junit.jupiter.api.extension.ExtendWith; + + import static org.junit.jupiter.api.Assertions.assertEquals; + + @ExtendWith(JMockitExtension.class) + class MyTest { + @Mocked + Object myObject; + + void test() { + new Expectations() {{ + myObject.hashCode(); + result = 100; + myObject.toString(); + result = new Delegate() { + @SuppressWarnings("unused") + String toString() { + String a = "bla"; + return a + "foo"; + } + }; + }}; + myObject.toString(); + } + } + """, + """ + import mockit.Delegate; + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mock; + import org.mockito.junit.jupiter.MockitoExtension; + + import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.mockito.Mockito.when; + + @ExtendWith(MockitoExtension.class) + class MyTest { + @Mock + Object myObject; + + void test() { + when(myObject.hashCode()).thenReturn(100); + when(myObject.toString()).thenReturn(new Delegate() { + @SuppressWarnings("unused") + String toString() { + String a = "bla"; + return a + "foo"; + } + }); + myObject.toString(); + } + } + """ + ) + ); + } + + @Test + void whenClassArgumentMatcher() { + //language=java + rewriteRun( + spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), + java( + """ + import java.util.List; + + class MyObject { + public String getSomeField(List input) { + return "X"; + } + public String getSomeOtherField(Object input) { + return "Y"; + } + } + """ + ), + java( + """ + import java.util.ArrayList; + import java.util.List; + + import mockit.Delegate; + import mockit.Mocked; + import mockit.Expectations; + import mockit.integration.junit5.JMockitExtension; + import org.junit.jupiter.api.extension.ExtendWith; + + @ExtendWith(JMockitExtension.class) + class MyTest { + @Mocked + MyObject myObject; + + void test() { + new Expectations() {{ + myObject.getSomeField((List) any); + result = new Delegate() { + String getSomeOtherField(List input) { + input.add("foo"); + return input.toString(); + } + }; + }}; + myObject.getSomeField(new ArrayList<>()); + myObject.getSomeOtherField(new Object()); + } + } + """, + """ + import java.util.ArrayList; + import java.util.List; + + import mockit.Delegate; + + import static org.mockito.Mockito.anyList; + import static org.mockito.Mockito.when; + + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mock; + import org.mockito.junit.jupiter.MockitoExtension; + + @ExtendWith(MockitoExtension.class) + class MyTest { + @Mock + MyObject myObject; + + void test() { + when(myObject.getSomeField(anyList())).thenReturn(new Delegate() { + String getSomeOtherField(List input) { + input.add("foo"); + return input.toString(); + } + }); + myObject.getSomeField(new ArrayList<>()); + myObject.getSomeOtherField(new Object()); + } + } + """ + ) + ); + } + +} diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java index fcc8bece2..1127c0c64 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java @@ -1474,4 +1474,73 @@ void test() { ) ); } + + @Test + void whenComments() { + //language=java + rewriteRun( + java( + """ + class MyObject { + public String getSomeStringField() { + return "X"; + } + } + """ + ), + java( + """ + import mockit.Expectations; + import mockit.Mocked; + import mockit.integration.junit5.JMockitExtension; + import org.junit.jupiter.api.extension.ExtendWith; + + import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.junit.jupiter.api.Assertions.assertNull; + + @ExtendWith(JMockitExtension.class) + class MyTest { + @Mocked + MyObject myObject; + + void test() { + new Expectations() {{ + // comments for this line below + myObject.getSomeStringField(); + result = "a"; + }}; + assertEquals("a", myObject.getSomeStringField()); + new Expectations() {{ + myObject.getSomeStringField(); + result = "b"; + }}; + assertEquals("b", myObject.getSomeStringField()); + } + } + """, + """ + import org.junit.jupiter.api.extension.ExtendWith; + import org.mockito.Mock; + import org.mockito.junit.jupiter.MockitoExtension; + + import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.junit.jupiter.api.Assertions.assertNull; + import static org.mockito.Mockito.when; + + @ExtendWith(MockitoExtension.class) + class MyTest { + @Mock + MyObject myObject; + + void test() { + when(myObject.getSomeStringField()).thenReturn("a"); + assertEquals("a", myObject.getSomeStringField()); + when(myObject.getSomeStringField()).thenReturn("b"); + assertEquals("b", myObject.getSomeStringField()); + } + } + """ + ) + ); + } } From 55bfec000496de840147609111b725591dfac8a9 Mon Sep 17 00:00:00 2001 From: Shivani Sharma Date: Sat, 3 Aug 2024 23:23:20 +1000 Subject: [PATCH 2/6] Update JMockitDelegateToMockitoTest.java Modify test cases so that the tests fail with expected output of Delegate migration --- .../jmockit/JMockitDelegateToMockitoTest.java | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java index 291e0fa80..b9bf127d6 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java @@ -15,10 +15,10 @@ */ package org.openrewrite.java.testing.jmockit; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import org.openrewrite.test.TypeValidation; import static org.openrewrite.java.Assertions.java; import static org.openrewrite.java.testing.jmockit.JMockitTestUtils.setDefaultParserSettings; @@ -26,8 +26,9 @@ /** * At the moment, JMockit Delegates are not migrated to mockito. What I'm seeing is that they are being trashed * with the template being printed out. These tests were written to try to replicate this issue, however I was unable to. - * They may help anyone adding feature for Delegate migration. + * They may help anyone who wants to add Delegate migration. */ +@Disabled class JMockitDelegateToMockitoTest implements RewriteTest { @Override @@ -39,7 +40,6 @@ public void defaults(RecipeSpec spec) { void whenNoArgsVoidMethod() { //language=java rewriteRun( - spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), java( """ import mockit.Expectations; @@ -80,10 +80,8 @@ class MyTest { Object myObject; void test() { - when(myObject.wait()).thenReturn(new Delegate() { - public void wait() { + when(myObject.wait()).thenAnswer(invocation -> { System.out.println("bla"); - } }); myObject.wait(); } @@ -97,7 +95,6 @@ public void wait() { void whenHasArgsVoidMethod() { //language=java rewriteRun( - spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), java( """ import mockit.Expectations; @@ -143,11 +140,9 @@ class MyTest { Object myObject; void test() { - when(myObject.wait(anyLong())).thenReturn(new Delegate() { - void wait(long timeoutMs) { - System.out.println("bla"); - System.out.println("bla"); - } + when(myObject.wait(anyLong())).thenAnswer(invocation -> { + System.out.println("bla"); + System.out.println("bla"); }); myObject.wait(); } @@ -161,7 +156,6 @@ void wait(long timeoutMs) { void whenNoArgsNonVoidMethod() { //language=java rewriteRun( - spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), java( """ import mockit.Expectations; @@ -206,11 +200,9 @@ class MyTest { Object myObject; void test() { - when(myObject.toString()).thenReturn(new Delegate() { - String toString() { - String a = "bla"; - return a + "foo"; - } + when(myObject.toString()).thenAnswer(invocation -> { + String a = "bla"; + return a + "foo"; }); myObject.toString(); } @@ -224,7 +216,6 @@ String toString() { void whenMultipleStatementsWithAnnotation() { //language=java rewriteRun( - spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), java( """ import mockit.Expectations; @@ -273,12 +264,9 @@ class MyTest { void test() { when(myObject.hashCode()).thenReturn(100); - when(myObject.toString()).thenReturn(new Delegate() { - @SuppressWarnings("unused") - String toString() { - String a = "bla"; - return a + "foo"; - } + when(myObject.toString()).thenAnswer(invocation -> { + String a = "bla"; + return a + "foo"; }); myObject.toString(); } @@ -292,7 +280,6 @@ String toString() { void whenClassArgumentMatcher() { //language=java rewriteRun( - spec -> spec.afterTypeValidationOptions(TypeValidation.builder().methodInvocations(false).build()), java( """ import java.util.List; @@ -357,11 +344,10 @@ class MyTest { MyObject myObject; void test() { - when(myObject.getSomeField(anyList())).thenReturn(new Delegate() { - String getSomeOtherField(List input) { - input.add("foo"); - return input.toString(); - } + when(myObject.getSomeField(anyList())).thenAnswer(invocation -> { + List input = invocation.getArgument(0); + input.add("foo"); + return input.toString(); }); myObject.getSomeField(new ArrayList<>()); myObject.getSomeOtherField(new Object()); From 197e25a21abca33b0f0d4ea47d5116db3633572d Mon Sep 17 00:00:00 2001 From: Shivani Sharma Date: Sat, 3 Aug 2024 23:27:04 +1000 Subject: [PATCH 3/6] Update JMockitExpectationsToMockitoTest.java Modify test to prove that comments migration is not supported within expectations, and this may be useful for someone who is adding this feature later. Disable test. --- .../java/testing/jmockit/JMockitExpectationsToMockitoTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java index 1127c0c64..70b2daa5f 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.testing.jmockit; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; @@ -1475,6 +1476,7 @@ void test() { ); } + @Disabled // comment migration not supported yet @Test void whenComments() { //language=java @@ -1533,6 +1535,7 @@ class MyTest { MyObject myObject; void test() { + // comments for this line below when(myObject.getSomeStringField()).thenReturn("a"); assertEquals("a", myObject.getSomeStringField()); when(myObject.getSomeStringField()).thenReturn("b"); From 96fb38348be2d7e1e79abd8bdcf1c35916617227 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 3 Aug 2024 19:46:13 +0200 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../java/testing/jmockit/JMockitDelegateToMockitoTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java index b9bf127d6..30699e653 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -36,6 +37,7 @@ public void defaults(RecipeSpec spec) { setDefaultParserSettings(spec); } + @DocumentExample @Test void whenNoArgsVoidMethod() { //language=java From c4e8d4a3813795264989a5a1370bd09197b2de24 Mon Sep 17 00:00:00 2001 From: Shivani Sharma Date: Sun, 4 Aug 2024 11:22:56 +1000 Subject: [PATCH 5/6] Update JMockitDelegateToMockitoTest.java Modify tests to account for stubbing void methods using doAnswer instead of thenAnswer. Remove unnecessary imports --- .../jmockit/JMockitDelegateToMockitoTest.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java index 30699e653..6988d9574 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java @@ -60,7 +60,7 @@ void test() { myObject.wait(); result = new Delegate() { public void wait() { - System.out.println("bla"); + System.out.println("foo"); } }; }}; @@ -82,9 +82,10 @@ class MyTest { Object myObject; void test() { - when(myObject.wait()).thenAnswer(invocation -> { - System.out.println("bla"); - }); + doAnswer(invocation -> { + System.out.println("foo"); + return null; + }).when(myObject).wait(); myObject.wait(); } } @@ -105,8 +106,6 @@ void whenHasArgsVoidMethod() { import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - import static org.junit.jupiter.api.Assertions.assertEquals; - @ExtendWith(JMockitExtension.class) class MyTest { @Mocked @@ -117,8 +116,8 @@ void test() { myObject.wait(anyLong); result = new Delegate() { void wait(long timeoutMs) { - System.out.println("bla"); - System.out.println("bla"); + System.out.println("foo"); + System.out.println("bar"); } }; }}; @@ -132,7 +131,6 @@ void wait(long timeoutMs) { import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.anyLong; import static org.mockito.Mockito.when; @@ -142,10 +140,11 @@ class MyTest { Object myObject; void test() { - when(myObject.wait(anyLong())).thenAnswer(invocation -> { - System.out.println("bla"); - System.out.println("bla"); - }); + doAnswer(invocation -> { + System.out.println("foo"); + System.out.println("bar"); + return null; + }).when(myObject).wait(anyLong()); myObject.wait(); } } @@ -178,12 +177,12 @@ void test() { myObject.toString(); result = new Delegate() { String toString() { - String a = "bla"; - return a + "foo"; + String a = "foo"; + return a + "bar"; } }; }}; - myObject.toString(); + assertEquals("foobar", myObject.toString()); } } """, @@ -203,10 +202,10 @@ class MyTest { void test() { when(myObject.toString()).thenAnswer(invocation -> { - String a = "bla"; - return a + "foo"; + String a = "foo"; + return a + "bar"; }); - myObject.toString(); + assertEquals("foobar", myObject.toString()); } } """ @@ -241,12 +240,13 @@ void test() { result = new Delegate() { @SuppressWarnings("unused") String toString() { - String a = "bla"; - return a + "foo"; + String a = "foo"; + return a + "bar"; } }; }}; - myObject.toString(); + assertEquals(100, myObject.hashCode()); + assertEquals("foobar", myObject.toString()); } } """, @@ -267,10 +267,11 @@ class MyTest { void test() { when(myObject.hashCode()).thenReturn(100); when(myObject.toString()).thenAnswer(invocation -> { - String a = "bla"; - return a + "foo"; + String a = "foo"; + return a + "bar"; }); - myObject.toString(); + assertEquals(100, myObject.hashCode()); + assertEquals("foobar", myObject.toString()); } } """ From 629469cb17d96543356db4e97f29728530038919 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 4 Aug 2024 15:17:30 +0200 Subject: [PATCH 6/6] Tag tests with associated issue --- .../jmockit/JMockitDelegateToMockitoTest.java | 20 ++++++----- .../JMockitExpectationsToMockitoTest.java | 34 +++++++++---------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java index 6988d9574..e4ad77bbd 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitDelegateToMockitoTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; +import org.openrewrite.Issue; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -30,6 +31,7 @@ * They may help anyone who wants to add Delegate migration. */ @Disabled +@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/522") class JMockitDelegateToMockitoTest implements RewriteTest { @Override @@ -49,7 +51,7 @@ void whenNoArgsVoidMethod() { import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - + @ExtendWith(JMockitExtension.class) class MyTest { @Mocked @@ -75,7 +77,7 @@ public void wait() { import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) class MyTest { @Mock @@ -105,7 +107,7 @@ void whenHasArgsVoidMethod() { import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - + @ExtendWith(JMockitExtension.class) class MyTest { @Mocked @@ -133,7 +135,7 @@ void wait(long timeoutMs) { import static org.mockito.Mockito.anyLong; import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) class MyTest { @Mock @@ -164,7 +166,7 @@ void whenNoArgsNonVoidMethod() { import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - + import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(JMockitExtension.class) @@ -194,7 +196,7 @@ String toString() { import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) class MyTest { @Mock @@ -224,7 +226,7 @@ void whenMultipleStatementsWithAnnotation() { import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - + import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(JMockitExtension.class) @@ -258,7 +260,7 @@ String toString() { import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; - + @ExtendWith(MockitoExtension.class) class MyTest { @Mock @@ -333,7 +335,7 @@ String getSomeOtherField(List input) { import java.util.List; import mockit.Delegate; - + import static org.mockito.Mockito.anyList; import static org.mockito.Mockito.when; diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java index 70b2daa5f..c39233d20 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java @@ -42,7 +42,7 @@ void whenTimesAndResult() { import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - + import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(JMockitExtension.class) @@ -189,8 +189,8 @@ void whenHasResultNoTimes() { import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; import org.junit.jupiter.api.extension.ExtendWith; - - import static org.junit.jupiter.api.Assertions.assertEquals; + + import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(JMockitExtension.class) class MyTest { @@ -210,8 +210,8 @@ void test() { import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - - import static org.junit.jupiter.api.Assertions.assertEquals; + + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) @@ -1065,7 +1065,7 @@ void whenMinTimes() { //language=java rewriteRun( java( - """ + """ import mockit.Expectations; import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; @@ -1075,7 +1075,7 @@ void whenMinTimes() { class MyTest { @Mocked Object myObject; - + void test() { new Expectations() {{ myObject.wait(anyLong, anyInt); @@ -1085,7 +1085,7 @@ void test() { } } """, - """ + """ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -1096,7 +1096,7 @@ void test() { class MyTest { @Mock Object myObject; - + void test() { myObject.wait(10L, 10); verify(myObject, atLeast(2)).wait(anyLong(), anyInt()); @@ -1112,7 +1112,7 @@ void whenMaxTimes() { //language=java rewriteRun( java( - """ + """ import mockit.Expectations; import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; @@ -1122,7 +1122,7 @@ void whenMaxTimes() { class MyTest { @Mocked Object myObject; - + void test() { new Expectations() {{ myObject.wait(anyLong, anyInt); @@ -1132,7 +1132,7 @@ void test() { } } """, - """ + """ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -1143,7 +1143,7 @@ void test() { class MyTest { @Mock Object myObject; - + void test() { myObject.wait(10L, 10); verify(myObject, atMost(5)).wait(anyLong(), anyInt()); @@ -1159,7 +1159,7 @@ void whenMinTimesMaxTimes() { //language=java rewriteRun( java( - """ + """ import mockit.Expectations; import mockit.Mocked; import mockit.integration.junit5.JMockitExtension; @@ -1169,7 +1169,7 @@ void whenMinTimesMaxTimes() { class MyTest { @Mocked Object myObject; - + void test() { new Expectations() {{ myObject.wait(anyLong, anyInt); @@ -1180,7 +1180,7 @@ void test() { } } """, - """ + """ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -1191,7 +1191,7 @@ void test() { class MyTest { @Mock Object myObject; - + void test() { myObject.wait(10L, 10); verify(myObject, atLeast(1)).wait(anyLong(), anyInt());