Skip to content

Instantly share code, notes, and snippets.

@kingargyle
Created February 1, 2017 15:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingargyle/c960487194bc356019099ffdff2756fb to your computer and use it in GitHub Desktop.
Save kingargyle/c960487194bc356019099ffdff2756fb to your computer and use it in GitHub Desktop.
Self Returning Answer for Mockito
public class SelfReturningAnswer implements Answer<Object> {
public Object answer(InvocationOnMock invocation) throws Throwable {
Object mock = invocation.getMock();
if( invocation.getMethod().getReturnType().isInstance( mock )){
return mock;
}
else{
return RETURNS_DEFAULTS.get().answer(invocation);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment