1 3 package org.jmock.util; 4 5 import org.jmock.core.CoreMock; 6 import org.jmock.core.Formatting; 7 import org.jmock.core.Invocation; 8 import org.jmock.core.InvocationMocker; 9 import org.jmock.core.matcher.StatelessInvocationMatcher; 10 import org.jmock.core.stub.CustomStub; 11 12 13 public class Dummy 14 { 15 private Dummy() { 16 17 } 18 19 public static Object newDummy( Class interfaceClass ) { 20 return newDummy(interfaceClass, "dummy" + Formatting.classShortName(interfaceClass)); 21 } 22 23 public static Object newDummy( final Class interfaceClass, final String name ) { 24 CoreMock mock = new CoreMock(interfaceClass, name); 25 InvocationMocker mocker = new InvocationMocker(); 26 27 mocker.addMatcher(new StatelessInvocationMatcher() 28 { 29 public boolean matches( Invocation invocation ) { 30 return invocation.invokedMethod.getDeclaringClass() == interfaceClass; 31 } 32 33 public StringBuffer describeTo( StringBuffer buf ) { 34 return buf.append("any invokedMethod declared in " + interfaceClass); 35 } 36 }); 37 mocker.setStub(new CustomStub("dummy invokedMethod") 38 { 39 public Object invoke( Invocation invocation ) throws Throwable { 40 throw new NotImplementedException(invocation.invokedMethod.getName() + "called on " + name); 41 } 42 }); 43 44 mock.addInvokable(mocker); 45 46 return mock.proxy(); 47 } 48 49 public static Object newDummy( final String name ) { 50 return new Object () 51 { 52 public String toString() { 53 return name; 54 } 55 }; 56 } 57 } 58 | Popular Tags |