Created
February 1, 2017 15:15
-
-
Save kingargyle/c960487194bc356019099ffdff2756fb to your computer and use it in GitHub Desktop.
Self Returning Answer for Mockito
This file contains hidden or 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
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