Skip to content

Instantly share code, notes, and snippets.

@nurkiewicz
Created April 26, 2013 16:13
Show Gist options
  • Save nurkiewicz/5468453 to your computer and use it in GitHub Desktop.
Save nurkiewicz/5468453 to your computer and use it in GitHub Desktop.
import static org.mockito.Mockito.doAnswer;
//...
doAnswer(slowly()).when(timeConsumingExternalServiceMock).process();
//...
private static Answer<Object> slowly() {
return new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Throwable {
// Simulation of connection to external services
LOGGER.debug("Sleeping");
Thread.sleep(5000);
LOGGER.debug("Stopped Sleeping");
return null;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment