Skip to content

Commit

Permalink
add tests in unit tests for expectations because the change in Argume…
Browse files Browse the repository at this point in the history
…ntMatchersRewrite.java affects Expectations too
  • Loading branch information
yurii-yu committed Sep 29, 2024
1 parent 7314333 commit e0a06f5
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ public String getSomeField(List<String> input) {
public String getSomeOtherField(Object input) {
return "Y";
}
public String getSomeArrayField(Object input) {
return "Z";
}
}
"""
),
Expand All @@ -694,9 +697,12 @@ void test() {
result = null;
myObject.getSomeOtherField((Object) any);
result = null;
myObject.getSomeArrayField((byte[]) any);
result = null;
}};
assertNull(myObject.getSomeField(new ArrayList<>()));
assertNull(myObject.getSomeOtherField(new Object()));
assertNull(myObject.getSomeArrayField(new byte[0]));
}
}
""",
Expand All @@ -719,8 +725,10 @@ class MyTest {
void test() {
when(myObject.getSomeField(anyList())).thenReturn(null);
when(myObject.getSomeOtherField(any(Object.class))).thenReturn(null);
when(myObject.getSomeArrayField(any(byte[].class))).thenReturn(null);
assertNull(myObject.getSomeField(new ArrayList<>()));
assertNull(myObject.getSomeOtherField(new Object()));
assertNull(myObject.getSomeArrayField(new byte[0]));
}
}
"""
Expand Down Expand Up @@ -1549,6 +1557,57 @@ void test() {
);
}

@Test
void whenWithRedundantThisModifier() {
//language=java
rewriteRun(
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
Object myObject;
void test() {
new Expectations() {{
myObject.wait(this.anyLong, anyInt);
}};
myObject.wait();
}
}
""",
"""
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.*;
@ExtendWith(MockitoExtension.class)
class MyTest {
@Mock
Object myObject;
void test() {
myObject.wait();
verify(myObject).wait(anyLong(), anyInt());
}
}
"""
)
);
}

@Disabled // comment migration not supported yet
@Test
void whenComments() {
Expand Down

0 comments on commit e0a06f5

Please sign in to comment.