Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Oct 22, 2024
1 parent 8a6982b commit 36c085a
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.testing.jmockit.JMockitTestUtils.setDefaultParserSettings;

class JMockitAnnotatedArgumentToMockitoTest extends JMockitTestBase {
class JMockitAnnotatedArgumentToMockitoTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
setDefaultParserSettings(spec);
}

@DocumentExample
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

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 who wants to add Delegate migration.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
@Disabled
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/522")
class JMockitDelegateToMockitoTest extends JMockitTestBase {
class JMockitDelegateToMockitoTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
setDefaultParserSettings(spec);
}

@DocumentExample
@Test
Expand All @@ -43,12 +52,12 @@ void whenNoArgsVoidMethod() {
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();
Expand All @@ -67,14 +76,14 @@ public void wait() {
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() {
doAnswer(invocation -> {
System.out.println("foo");
Expand All @@ -99,12 +108,12 @@ void whenHasArgsVoidMethod() {
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(anyLong);
Expand All @@ -124,15 +133,15 @@ void wait(long timeoutMs) {
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class MyTest {
@Mock
Object myObject;
void test() {
doAnswer(invocation -> {
System.out.println("foo");
Expand All @@ -158,14 +167,14 @@ 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)
class MyTest {
@Mocked
Object myObject;
void test() {
new Expectations() {{
myObject.toString();
Expand All @@ -185,15 +194,15 @@ String toString() {
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()).thenAnswer(invocation -> {
String a = "foo";
Expand All @@ -218,14 +227,14 @@ 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)
class MyTest {
@Mocked
Object myObject;
void test() {
new Expectations() {{
myObject.hashCode();
Expand All @@ -249,15 +258,15 @@ String toString() {
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()).thenAnswer(invocation -> {
Expand All @@ -280,7 +289,7 @@ void whenClassArgumentMatcher() {
java(
"""
import java.util.List;
class MyObject {
public String getSomeField(List<String> input) {
return "X";
Expand All @@ -295,18 +304,18 @@ public String getSomeOtherField(Object input) {
"""
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<String>) any);
Expand All @@ -325,21 +334,21 @@ String getSomeOtherField(List<String> input) {
"""
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())).thenAnswer(invocation -> {
List<String> input = invocation.getArgument(0);
Expand Down
Loading

0 comments on commit 36c085a

Please sign in to comment.