Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-dthomson committed Oct 30, 2023
1 parent 960fa25 commit 22450a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private J.Block applyTemplate(ExecutionContext ctx, List<Object> templateParams,
staticImport = "org.mockito.Mockito.doNothing";
}
rewriteArgumentMatchers(ctx, templateParams);
return JavaTemplate.builder(getTemplate(result))
return JavaTemplate.builder(getMockitoStatementTemplate(result))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "mockito-core-3.12"))
.staticImports(staticImport)
.build()
Expand Down Expand Up @@ -203,10 +203,7 @@ private static boolean isArgumentMatcher(Expression expression) {
return JMOCKIT_ARGUMENT_MATCHERS.contains(identifier.getSimpleName());
}

/*
* Based on the result type, we need to use a different template.
*/
private static String getTemplate(Expression result) {
private static String getMockitoStatementTemplate(Expression result) {
if (result == null) {
return VOID_RESULT_TEMPLATE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void jMockitExpectationsToMockitoWhenMultipleStatements() {
java(
"""
class MyObject {
public String getSomeStringField(String input, String otherInput) {
public String getSomeStringField(String input, long otherInput) {
return "X";
}
public int getSomeIntField() {
Expand Down Expand Up @@ -499,13 +499,13 @@ void test() {
myOtherObject.getSomeObjectField();
result = null;
myObject.doSomething();
myOtherObject.getSomeStringField(anyString, anyString);
myOtherObject.getSomeStringField(anyString, anyLong);
result = "foo";
}};
assertEquals(10, myObject.getSomeIntField());
assertNull(myOtherObject.getSomeObjectField());
myObject.doSomething();
assertEquals("foo", myOtherObject.getSomeStringField("bar", "bazz"));
assertEquals("foo", myOtherObject.getSomeStringField("bar", 10L));
}
}
""",
Expand All @@ -530,11 +530,11 @@ void test() {
when(myObject.getSomeIntField()).thenReturn(10);
when(myOtherObject.getSomeObjectField()).thenReturn(null);
doNothing().when(myObject.doSomething());
when(myOtherObject.getSomeStringField(anyString(), anyString())).thenReturn("foo");
when(myOtherObject.getSomeStringField(anyString(), anyLong())).thenReturn("foo");
assertEquals(10, myObject.getSomeIntField());
assertNull(myOtherObject.getSomeObjectField());
myObject.doSomething();
assertEquals("foo", myOtherObject.getSomeStringField("bar", "bazz"));
assertEquals("foo", myOtherObject.getSomeStringField("bar", 10L));
}
}
"""
Expand Down

0 comments on commit 22450a1

Please sign in to comment.