From 91bc4a09cac9d805eedc3759a96868ced6fcce8b Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 14 Dec 2024 00:05:55 +0100 Subject: [PATCH] Run `MockitoBestPractices` after JMockit migration Fixes #561 --- .../resources/META-INF/rewrite/jmockit.yml | 1 + .../jmockit/JMockitMockUpToMockitoTest.java | 136 ++++----- ...kitNonStrictExpectationsToMockitoTest.java | 268 +++++++++--------- .../testing/jmockit/JMockitTestUtils.java | 5 +- 4 files changed, 201 insertions(+), 209 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jmockit.yml b/src/main/resources/META-INF/rewrite/jmockit.yml index d1ee335d7..d059a69d8 100644 --- a/src/main/resources/META-INF/rewrite/jmockit.yml +++ b/src/main/resources/META-INF/rewrite/jmockit.yml @@ -52,3 +52,4 @@ recipeList: - org.openrewrite.maven.ExcludeDependency: groupId: org.jmockit artifactId: jmockit + - org.openrewrite.java.testing.mockito.MockitoBestPractices diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockitoTest.java index 49c9ed48b..2b292aeed 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockitoTest.java @@ -43,17 +43,17 @@ void mockUpStaticMethodTest() { import mockit.MockUp; import static org.junit.Assert.assertEquals; import org.junit.Test; - + public class MockUpTest { @Test public void test() { new MockUp() { - + @Mock public int staticMethod() { return 1024; } - + @Mock public int staticMethod(int v) { return 128; @@ -62,12 +62,12 @@ public int staticMethod(int v) { assertEquals(1024, MyClazz.staticMethod()); assertEquals(128, MyClazz.staticMethod(0)); } - + public static class MyClazz { public static int staticMethod() { return 0; } - + public static int staticMethod(int v) { return 1; } @@ -75,12 +75,12 @@ public static int staticMethod(int v) { } """, """ import static org.junit.Assert.assertEquals; - import static org.mockito.ArgumentMatchers.*; - import static org.mockito.Mockito.*; - + import static org.mockito.ArgumentMatchers.anyInt; + import static org.mockito.Mockito.mockStatic; + import org.junit.Test; import org.mockito.MockedStatic; - + public class MockUpTest { @Test public void test() { @@ -91,12 +91,12 @@ public void test() { assertEquals(128, MyClazz.staticMethod(0)); } } - + public static class MyClazz { public static int staticMethod() { return 0; } - + public static int staticMethod(int v) { return 1; } @@ -117,7 +117,7 @@ public static class Foo { public String getMsg() { return "foo"; } - + public String getMsg(String echo) { return "foo" + echo; } @@ -132,7 +132,7 @@ public static class Bar { public String getMsg() { return "bar"; } - + public String getMsg(String echo) { return "bar" + echo; } @@ -148,7 +148,7 @@ public String getMsg(String echo) { import mockit.Mock; import mockit.MockUp; import static org.junit.Assert.assertEquals; - + public class MockUpTest { @Test public void test() { @@ -188,7 +188,7 @@ public String getMsg(String echo) { import static org.mockito.Answers.CALLS_REAL_METHODS; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; - + public class MockUpTest { @Test public void test() { @@ -224,22 +224,22 @@ void mockUpInnerStatementTest() { """ import mockit.Mock; import mockit.MockUp; - + import org.junit.Test; import static org.junit.Assert.assertEquals; - + public class MockUpTest { @Test public void test() { new MockUp() { final String msg = "newMsg"; - + @Mock public String getMsg() { return msg; } }; - + // Should ignore the newClass statement new Runnable() { @Override @@ -249,7 +249,7 @@ public void run() { }; assertEquals("newMsg", new MyClazz().getMsg()); } - + public static class MyClazz { public String getMsg() { return "msg"; @@ -259,12 +259,12 @@ public String getMsg() { """, """ import org.junit.Test; import org.mockito.MockedConstruction; - + import static org.junit.Assert.assertEquals; import static org.mockito.AdditionalAnswers.delegatesTo; import static org.mockito.Answers.CALLS_REAL_METHODS; import static org.mockito.Mockito.*; - + public class MockUpTest { @Test public void test() { @@ -272,7 +272,7 @@ public void test() { MyClazz mockMyClazz = mock(MyClazz.class, CALLS_REAL_METHODS); doAnswer(invocation -> msg).when(mockMyClazz).getMsg(); try (MockedConstruction mockConsMyClazz = mockConstructionWithAnswer(MyClazz.class, delegatesTo(mockMyClazz))) { - + // Should ignore the newClass statement new Runnable() { @Override @@ -283,7 +283,7 @@ public void run() { assertEquals("newMsg", new MyClazz().getMsg()); } } - + public static class MyClazz { public String getMsg() { return "msg"; @@ -303,7 +303,7 @@ void mockUpVoidTest() { import mockit.MockUp; import static org.junit.Assert.assertEquals; import org.junit.Test; - + public class MockUpTest { @Test public void test() { @@ -312,37 +312,37 @@ public void test() { public void changeMsg() { MockUpClass.Save.msg = "mockMsg"; } - + @Mock public void changeText(String text) { MockUpClass.Save.text = "mockText"; } }; - + assertEquals("mockMsg", new MockUpClass().getMsg()); assertEquals("mockText", new MockUpClass().getText()); } - + public static class MockUpClass { public static class Save { public static String msg = "msg"; public static String text = "text"; } - + public final String getMsg() { changeMsg(); return Save.msg; } - + public void changeMsg() { Save.msg = "newMsg"; } - + public String getText() { changeText("newText"); return Save.text; } - + public static void changeText(String text) { Save.text = text; } @@ -353,13 +353,13 @@ public static void changeText(String text) { import static org.junit.Assert.assertEquals; import static org.mockito.AdditionalAnswers.delegatesTo; import static org.mockito.Answers.CALLS_REAL_METHODS; - import static org.mockito.ArgumentMatchers.*; + import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; - + import org.junit.Test; import org.mockito.MockedConstruction; import org.mockito.MockedStatic; - + public class MockUpTest { @Test public void test() { @@ -374,32 +374,32 @@ public void test() { MockUpClass.Save.text = "mockText"; return null; }); - + assertEquals("mockMsg", new MockUpClass().getMsg()); assertEquals("mockText", new MockUpClass().getText()); } } - + public static class MockUpClass { public static class Save { public static String msg = "msg"; public static String text = "text"; } - + public final String getMsg() { changeMsg(); return Save.msg; } - + public void changeMsg() { Save.msg = "newMsg"; } - + public String getText() { changeText("newText"); return Save.text; } - + public static void changeText(String text) { Save.text = text; } @@ -419,7 +419,7 @@ void mockUpAtSetUpWithoutTearDownTest() { import mockit.Mock; import mockit.MockUp; import static org.junit.Assert.assertEquals; - + public class MockUpTest { @Before public void setUp() { @@ -430,12 +430,12 @@ public String getMsg() { } }; } - + @Test public void test() { assertEquals("mockMsg", new MyClazz().getMsg()); } - + public static class MyClazz { public String getMsg() { return "msg"; @@ -452,27 +452,27 @@ public String getMsg() { import static org.mockito.AdditionalAnswers.delegatesTo; import static org.mockito.Answers.CALLS_REAL_METHODS; import static org.mockito.Mockito.*; - + public class MockUpTest { private MockedConstruction mockConsMyClazz; - + @Before public void setUp() { MyClazz mockMyClazz = mock(MyClazz.class, CALLS_REAL_METHODS); doAnswer(invocation -> "mockMsg").when(mockMyClazz).getMsg(); mockConsMyClazz = mockConstructionWithAnswer(MyClazz.class, delegatesTo(mockMyClazz)); } - + @After public void tearDown() { mockConsMyClazz.closeOnDemand(); } - + @Test public void test() { assertEquals("mockMsg", new MyClazz().getMsg()); } - + public static class MyClazz { public String getMsg() { return "msg"; @@ -496,7 +496,7 @@ void mockUpAtSetUpWithTearDownTest() { import mockit.Mock; import mockit.MockUp; import static org.junit.Assert.assertEquals; - + public class MockUpTest { @Before public void setUp() { @@ -505,29 +505,29 @@ public void setUp() { public String getMsg() { return "mockMsg"; } - + @Mock public String getStaticMsg() { return "mockStaticMsg"; } }; } - + @After public void tearDown() { } - + @Test public void test() { assertEquals("mockMsg", new MyClazz().getMsg()); assertEquals("mockStaticMsg", MyClazz.getStaticMsg()); } - + public static class MyClazz { public String getMsg() { return "msg"; } - + public static String getStaticMsg() { return "staticMsg"; } @@ -544,11 +544,11 @@ public static String getStaticMsg() { import static org.mockito.AdditionalAnswers.delegatesTo; import static org.mockito.Answers.CALLS_REAL_METHODS; import static org.mockito.Mockito.*; - + public class MockUpTest { private MockedConstruction mockConsMyClazz; private MockedStatic mockStaticMyClazz; - + @Before public void setUp() { MyClazz mockMyClazz = mock(MyClazz.class, CALLS_REAL_METHODS); @@ -557,24 +557,24 @@ public void setUp() { mockStaticMyClazz = mockStatic(MyClazz.class); mockStaticMyClazz.when(() -> MyClazz.getStaticMsg()).thenAnswer(invocation -> "mockStaticMsg"); } - + @After public void tearDown() { mockConsMyClazz.closeOnDemand(); mockStaticMyClazz.closeOnDemand(); } - + @Test public void test() { assertEquals("mockMsg", new MyClazz().getMsg()); assertEquals("mockStaticMsg", MyClazz.getStaticMsg()); } - + public static class MyClazz { public String getMsg() { return "msg"; } - + public static String getStaticMsg() { return "staticMsg"; } @@ -594,9 +594,9 @@ void mockUpWithParamsTest() { import mockit.Mock; import mockit.MockUp; import org.junit.Test; - + import static org.junit.Assert.assertEquals; - + public class MockUpTest { @Test public void init() { @@ -608,7 +608,7 @@ public String getMsg(String foo, String bar, String unused) { }; assertEquals("foobar", new MyClazz().getMsg("foo", "bar", "unused")); } - + public static class MyClazz { public String getMsg(String foo, String bar, String unused) { return "msg"; @@ -619,13 +619,13 @@ public String getMsg(String foo, String bar, String unused) { """ import org.junit.Test; import org.mockito.MockedConstruction; - + import static org.junit.Assert.assertEquals; import static org.mockito.AdditionalAnswers.delegatesTo; import static org.mockito.Answers.CALLS_REAL_METHODS; - import static org.mockito.ArgumentMatchers.*; + import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.*; - + public class MockUpTest { @Test public void init() { @@ -639,7 +639,7 @@ public void init() { assertEquals("foobar", new MyClazz().getMsg("foo", "bar", "unused")); } } - + public static class MyClazz { public String getMsg(String foo, String bar, String unused) { return "msg"; diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitNonStrictExpectationsToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitNonStrictExpectationsToMockitoTest.java index 463746a26..baba75092 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitNonStrictExpectationsToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitNonStrictExpectationsToMockitoTest.java @@ -50,14 +50,14 @@ public String getSomeField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -71,16 +71,15 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertNull; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeField()).thenReturn(null); assertNull(myObject.getSomeField()); @@ -110,14 +109,14 @@ public int getSomeField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -136,16 +135,15 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeField()).thenReturn(10); assertEquals(10, myObject.getSomeField()); @@ -177,14 +175,14 @@ public String getSomeField(String s) { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField(anyString); @@ -198,15 +196,16 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; - import static org.mockito.Mockito.*; - + import static org.mockito.Mockito.anyString; + import static org.mockito.Mockito.lenient; + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeField(anyString())).thenReturn("foo"); assertEquals("foo", myObject.getSomeField("bar")); @@ -236,16 +235,16 @@ public String getSomeField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + String expected = "expected"; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -259,18 +258,17 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + String expected = "expected"; - + void test() { lenient().when(myObject.getSomeField()).thenReturn(expected); assertEquals(expected, myObject.getSomeField()); @@ -300,14 +298,14 @@ public Object getSomeField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertNotNull; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -321,16 +319,15 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeField()).thenReturn(new Object()); assertNotNull(myObject.getSomeField()); @@ -360,12 +357,12 @@ public String getSomeField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() throws RuntimeException { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -379,15 +376,14 @@ void test() throws RuntimeException { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() throws RuntimeException { lenient().when(myObject.getSomeField()).thenThrow(new RuntimeException()); myObject.getSomeField(); @@ -417,14 +413,14 @@ public String getSomeField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() throws RuntimeException { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -439,16 +435,15 @@ void test() throws RuntimeException { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() throws RuntimeException { lenient().when(myObject.getSomeField()).thenReturn("foo", "bar"); assertEquals("foo", myObject.getSomeField()); @@ -467,7 +462,7 @@ void whenClassArgumentMatcher() { java( """ import java.util.List; - + class MyObject { public String getSomeField(List input) { return "X"; @@ -482,19 +477,19 @@ public String getSomeOtherField(Object input) { """ import java.util.ArrayList; import java.util.List; - + import mockit.NonStrictExpectations; import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField((List) any); @@ -510,19 +505,19 @@ void test() { """ import java.util.ArrayList; import java.util.List; - + import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertNull; import static org.mockito.Mockito.*; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeField(anyList())).thenReturn(null); lenient().when(myObject.getSomeOtherField(any(Object.class))).thenReturn(null); @@ -542,7 +537,7 @@ void whenNoArguments() { java( """ import java.util.List; - + class MyObject { public String getSomeField() { return "X"; @@ -554,19 +549,19 @@ public String getSomeField() { """ import java.util.ArrayList; import java.util.List; - + import mockit.NonStrictExpectations; import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeField(); @@ -579,20 +574,19 @@ void test() { """ import java.util.ArrayList; import java.util.List; - + import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertNull; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeField()).thenReturn(null); assertNull(myObject.getSomeField()); @@ -611,7 +605,7 @@ void whenMixedArgumentMatcher() { java( """ import java.util.List; - + class MyObject { public String getSomeField(String s, String s2, String s3, long l1) { return "X"; @@ -623,19 +617,19 @@ public String getSomeField(String s, String s2, String s3, long l1) { """ import java.util.ArrayList; import java.util.List; - + import mockit.NonStrictExpectations; import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { String bazz = "bazz"; new NonStrictExpectations() {{ @@ -649,19 +643,19 @@ void test() { """ import java.util.ArrayList; import java.util.List; - + import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertNull; import static org.mockito.Mockito.*; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { String bazz = "bazz"; lenient().when(myObject.getSomeField(eq("foo"), anyString(), eq(bazz), eq(10L))).thenReturn(null); @@ -680,7 +674,7 @@ void whenSetupStatements() { java( """ class MyObject { - + public String getSomeField(String s) { return "X"; } @@ -696,26 +690,26 @@ public String getString() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { String a = "a"; String s = "s"; - + new NonStrictExpectations() {{ myObject.getSomeField(anyString); result = s; - + myObject.getString(); result = a; }}; - + assertEquals("s", myObject.getSomeField("foo")); assertEquals("a", myObject.getString()); } @@ -725,21 +719,22 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; - import static org.mockito.Mockito.*; - + import static org.mockito.Mockito.anyString; + import static org.mockito.Mockito.lenient; + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { String a = "a"; String s = "s"; lenient().when(myObject.getSomeField(anyString())).thenReturn(s); lenient().when(myObject.getString()).thenReturn(a); - + assertEquals("s", myObject.getSomeField("foo")); assertEquals("a", myObject.getString()); } @@ -768,14 +763,14 @@ public String getSomeField(String s) { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { String a = "a"; new NonStrictExpectations() {{ @@ -784,7 +779,7 @@ void test() { String b = "b"; result = s; }}; - + assertEquals("s", myObject.getSomeField("foo")); } } @@ -793,21 +788,22 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; - import static org.mockito.Mockito.*; - + import static org.mockito.Mockito.anyString; + import static org.mockito.Mockito.lenient; + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { String a = "a"; String s = "s"; String b = "b"; lenient().when(myObject.getSomeField(anyString())).thenReturn(s); - + assertEquals("s", myObject.getSomeField("foo")); } } @@ -835,14 +831,14 @@ public String getSomeField() { import mockit.Tested; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; - + @RunWith(JMockit.class) class MyTest { @Tested MyObject myObject; - + void test() { new NonStrictExpectations(myObject) {{ myObject.getSomeField(); @@ -856,16 +852,15 @@ void test() { import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @InjectMocks MyObject myObject; - + void test() { lenient().when(myObject.getSomeField()).thenReturn("foo"); assertEquals("foo", myObject.getSomeField()); @@ -902,18 +897,18 @@ public void doSomething() {} import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked Object myObject; - + @Mocked MyObject myOtherObject; - + void test() { new NonStrictExpectations() {{ myObject.hashCode(); @@ -935,19 +930,19 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.*; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock Object myObject; - + @Mock MyObject myOtherObject; - + void test() { lenient().when(myObject.hashCode()).thenReturn(10); lenient().when(myOtherObject.getSomeObjectField()).thenReturn(null); @@ -982,15 +977,15 @@ public String getSomeStringField() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked MyObject myObject; - + void test() { new NonStrictExpectations() {{ myObject.getSomeStringField(); @@ -1009,17 +1004,16 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.lenient; - import static org.mockito.Mockito.when; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock MyObject myObject; - + void test() { lenient().when(myObject.getSomeStringField()).thenReturn("a"); assertEquals("a", myObject.getSomeStringField()); @@ -1042,15 +1036,15 @@ void whenNoResultsNoTimes() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - + @RunWith(JMockit.class) class MyTest { @Mocked Object myObject; - + void test() { new NonStrictExpectations() {{ myObject.wait(anyLong); @@ -1063,15 +1057,15 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock Object myObject; - + void test() { myObject.wait(1L); } @@ -1091,12 +1085,12 @@ void whenTimes() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + @RunWith(JMockit.class) class MyTest { @Mocked Object myObject; - + void test() { new NonStrictExpectations() {{ myObject.wait(anyLong, anyInt); @@ -1112,14 +1106,14 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.mockito.Mockito.*; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock Object myObject; - + void test() { myObject.wait(10L, 10); myObject.wait(10L, 10); @@ -1142,12 +1136,12 @@ void whenTimesAndResult() { import mockit.Mocked; import mockit.integration.junit4.JMockit; import org.junit.runner.RunWith; - + @RunWith(JMockit.class) class MyTest { @Mocked Object myObject; - + void test() { new NonStrictExpectations() {{ myObject.toString(); @@ -1163,14 +1157,14 @@ void test() { import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - + import static org.mockito.Mockito.*; - + @RunWith(MockitoJUnitRunner.class) class MyTest { @Mock Object myObject; - + void test() { when(myObject.toString()).thenReturn("foo"); myObject.toString(); diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java index 9c2ac5f31..6bcdfe322 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitTestUtils.java @@ -42,9 +42,6 @@ static void setParserSettings(RecipeSpec spec, String... javaParserTestDependenc .classpathFromResources(new InMemoryExecutionContext(), javaParserTestDependencies )) - .recipeFromResource( - "/META-INF/rewrite/jmockit.yml", - "org.openrewrite.java.testing.jmockit.JMockitToMockito" - ); + .recipeFromResources("org.openrewrite.java.testing.jmockit.JMockitToMockito"); } }