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
The problem arises only when "inline mocking" is enabled (enabled as described in Mocking Final Types.)
Consider the following test case:
public static class MyService {
public synchronized void execute() {
System.out.println("Do something");
}
}
@Test
public void test() {
MyService service = spy(new MyService());
Thread t = new Thread() {
public void run() {
try {
// wait such that verify(service).execute() enters the method before us then invoke the service
Thread.sleep(1000);
service.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
verify(service, timeout(2000)).execute();
}
This test fails saying the execute() method has not been invoked before the timeout. After some investigations it appears that verify(service).execute() already holds a lock on the MyService instance preventing the async thread to access it.
On the other hand, everything works as expected when "inline mocking" is not enabled (test succeeds).
Is this scenario not supported ?
Can this be related to #2001 ?
Tested with Mockito 4.1.0 and OpenJDK 11.
The text was updated successfully, but these errors were encountered:
The problem arises only when "inline mocking" is enabled (enabled as described in Mocking Final Types.)
Consider the following test case:
This test fails saying the
execute()
method has not been invoked before the timeout. After some investigations it appears thatverify(service).execute()
already holds a lock on theMyService
instance preventing the async thread to access it.On the other hand, everything works as expected when "inline mocking" is not enabled (test succeeds).
Is this scenario not supported ?
Can this be related to #2001 ?
Tested with Mockito 4.1.0 and OpenJDK 11.
The text was updated successfully, but these errors were encountered: