You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I found a bug with the verify method. It seems that there is some async action behind the method. Here is a sample code with the main problem:
import static org.mockito.Mockito.verify;
import java.util.HashMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class TestClass {
@Mock
Validator validator;
@Test
public void validateTest() {
new SomeClass().myMethod(validator);
verify(validator).validate(new HashMap<String, String>(), "potatoe");
}
}
import java.util.HashMap;
import java.util.Map;
public class SomeClass {
public void myMethod (Validator validator) {
Map<String, String> map = new HashMap<>();
validator.validate(map, "potatoe");
map.put("tomatoe", "ketchup");
}
}
import java.util.Map;
public interface Validator {
public void validate(Map<String, String> map, String value);
}
Every time I execute the test I get the following message:
Argument(s) are different! Wanted:
validator.validate(
{},
"potatoe"
);
-> at com.ue.economyplayer.logic.impl.TestClass.validateTest(TestClass.java:21)
Actual invocations have different arguments:
validator.validate(
{"tomatoe" = "ketchup"},
"potatoe"
);
-> at com.ue.economyplayer.logic.impl.SomeClass.myMethod(SomeClass.java:10)
at com.ue.economyplayer.logic.impl.TestClass.validateTest(TestClass.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
The arguments are not matching, but the map is filled after the method invocation and should be empty at the invocation time.
Unfortunately, Map is one of the classes that Mockito relies on internally for its behavior. Stubbing Map will therefore lead to undefined behavior. Additionally, it is advised not to mock classes you don't own: https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-a-type-you-dont-own We are working on improving the user experience by working on a DoNotMock feature to avoid mocking classes/methods that are known to crash Mockito internals (#1833). Therefore, I am closing this as "Infeasible". Apologies for the uninformative exception that is thrown.
Hey,
I think I found a bug with the verify method. It seems that there is some async action behind the method. Here is a sample code with the main problem:
Every time I execute the test I get the following message:
The arguments are not matching, but the map is filled after the method invocation and should be empty at the invocation time.
My Environment:
JDK 1.8
JUnit 5
Mockito-Core 3.4.6
Mockito-JUnit-Jupiter 3.4.6
The text was updated successfully, but these errors were encountered: