Created
March 30, 2013 16:15
-
-
Save tgoossens/5277286 to your computer and use it in GitHub Desktop.
needs mockito library
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
public class StreamMock { | |
/** | |
* Will create a mock object. When one of the methods of this mock object is | |
* invoked, it will write information about this method-call to the given | |
* printstream. | |
* | |
* @param clazz | |
* @param out | |
* @return | |
*/ | |
public static <T> T streammock(final Class<T> clazz, final PrintStream out) { | |
final T t = Mockito.mock(clazz, new Answer<T>() { | |
@Override | |
public T answer(InvocationOnMock invocation) throws Throwable { | |
final String methodname = invocation.getMethod().getName(); | |
final String str = new StringBuilder() | |
.append("mock: ") | |
.append(invocation.getMethod().getDeclaringClass() | |
.getCanonicalName()).append(".") | |
.append(methodname) | |
.append(Arrays.asList(invocation.getArguments())) | |
.append(";").toString(); | |
out.println(str); | |
return null; | |
} | |
}); | |
return t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment