1 3 package org.jmock; 4 5 import org.jmock.core.*; 6 import org.jmock.core.matcher.InvokeAtLeastOnceMatcher; 7 import org.jmock.core.matcher.InvokeOnceMatcher; 8 import org.jmock.core.matcher.TestFailureMatcher; 9 import org.jmock.core.stub.ReturnStub; 10 import org.jmock.core.stub.StubSequence; 11 import org.jmock.core.stub.ThrowStub; 12 13 14 19 public abstract class MockObjectTestCase 20 extends MockObjectSupportTestCase 21 { 22 public MockObjectTestCase() { 23 } 24 25 public MockObjectTestCase( String name ) { 26 super(name); 27 } 28 29 public Mock mock( Class mockedType ) { 30 return mock(mockedType, defaultMockNameForType(mockedType)); 31 } 32 33 public Mock mock( Class mockedType, String roleName ) { 34 Mock newMock = new Mock(newCoreMock(mockedType, roleName)); 35 registerToVerify(newMock); 36 return newMock; 37 } 38 39 protected DynamicMock newCoreMock( Class mockedType, String roleName ) { 40 return new CoreMock(mockedType, roleName); 41 } 42 43 public String defaultMockNameForType( Class mockedType ) { 44 return "mock" + Formatting.classShortName(mockedType); 45 } 46 47 public Stub returnValue( Object o ) { 48 return new ReturnStub(o); 49 } 50 51 public Stub returnValue( boolean result ) { 52 return returnValue(new Boolean (result)); 53 } 54 55 public Stub returnValue( byte result ) { 56 return returnValue(new Byte (result)); 57 } 58 59 public Stub returnValue( char result ) { 60 return returnValue(new Character (result)); 61 } 62 63 public Stub returnValue( short result ) { 64 return returnValue(new Short (result)); 65 } 66 67 public Stub returnValue( int result ) { 68 return returnValue(new Integer (result)); 69 } 70 71 public Stub returnValue( long result ) { 72 return returnValue(new Long (result)); 73 } 74 75 public Stub returnValue( float result ) { 76 return returnValue(new Float (result)); 77 } 78 79 public Stub returnValue( double result ) { 80 return returnValue(new Double (result)); 81 } 82 83 public Stub throwException( Throwable throwable ) { 84 return new ThrowStub(throwable); 85 } 86 87 public InvocationMatcher once() { 88 return new InvokeOnceMatcher(); 89 } 90 91 public InvocationMatcher atLeastOnce() { 92 return new InvokeAtLeastOnceMatcher(); 93 } 94 95 public InvocationMatcher never() { 96 return new TestFailureMatcher("expect not called"); 97 } 98 99 public Stub onConsecutiveCalls( Stub stub1, Stub stub2 ) { 100 return new StubSequence(new Stub[]{stub1, stub2}); 101 } 102 103 public Stub onConsecutiveCalls( Stub stub1, Stub stub2, Stub stub3 ) { 104 return new StubSequence(new Stub[]{stub1, stub2, stub3}); 105 } 106 107 public Stub onConsecutiveCalls( Stub stub1, Stub stub2, Stub stub3, Stub stub4 ) { 108 return new StubSequence(new Stub[]{stub1, stub2, stub3, stub4}); 109 } 110 } 111 | Popular Tags |