Last active
October 27, 2023 23:48
-
-
Save aashreys/e828cfaa0ed2136dd1b33a1b1f96a986 to your computer and use it in GitHub Desktop.
Use Mockito to instantly execute handler runnables in your tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a handler which executes runnables immediately | |
Mockito.when(uiHandler.post(Mockito.any(Runnable.class))).thenAnswer( | |
new Answer<Object>() { | |
@Override | |
public Object answer(InvocationOnMock invocation) throws Throwable { | |
Runnable msg = invocation.getArgument(0); | |
msg.run(); | |
return null; | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment