public Object newDummy(Class dummyType) {
return newDummy(dummyType, "dummy" + Formatting.classShortName(dummyType));
}
public Object newDummy( final Class type, final String name ) {
DynamicMock mock = newCoreMock(type, name);
InvocationMocker mocker = new InvocationMocker();
mocker.addMatcher(new StatelessInvocationMatcher() {
public boolean matches( Invocation invocation ) {
return invocation.invokedMethod.getDeclaringClass() == type;
}
public StringBuffer describeTo( StringBuffer buf ) {
return buf.append("any invokedMethod declared in " + type);
}
});
mocker.setStub(new CustomStub("dummy invokedMethod") {
public Object invoke( Invocation invocation ) throws Throwable {
throw new NotImplementedException(invocation.invokedMethod.getName() + " called on " + name);
}
});
mock.addInvokable(mocker);
return mock.proxy();
}