1 package test.mockobjects.dynamic; 2 3 import com.mockobjects.*; 4 import com.mockobjects.dynamic.CallFactory; 5 import com.mockobjects.dynamic.Callable; 6 import com.mockobjects.dynamic.ConstraintMatcher; 7 8 public class MockCallFactory implements CallFactory{ 9 private ExpectationCounter myCreateReturnStubCalls = new ExpectationCounter("MockCallFactory.createReturnStub(Object)"); 10 private ReturnValues myActualCreateReturnStubReturnValues = new ReturnValues("MockCallFactory.createReturnStub(Object)", true); 11 private ExpectationList myCreateReturnStubParameter0Values = new ExpectationList("MockCallFactory.createReturnStub(Object) java.lang.Object"); 12 private ExpectationCounter myCreateThrowStubCalls = new ExpectationCounter("MockCallFactory.createThrowStub(Throwable)"); 13 private ReturnValues myActualCreateThrowStubReturnValues = new ReturnValues("MockCallFactory.createThrowStub(Throwable)", true); 14 private ExpectationList myCreateThrowStubParameter0Values = new ExpectationList("MockCallFactory.createThrowStub(Throwable) java.lang.Throwable"); 15 private ExpectationCounter myCreateVoidStubCalls = new ExpectationCounter("MockCallFactory.createVoidStub()"); 16 private ReturnValues myActualCreateVoidStubReturnValues = new ReturnValues("MockCallFactory.createVoidStub()", true); 17 private ExpectationCounter myCreateCallExpectationCalls = new ExpectationCounter("MockCallFactory.createCallExpectation(Callable)"); 18 private ReturnValues myActualCreateCallExpectationReturnValues = new ReturnValues("MockCallFactory.createCallExpectation(Callable)", true); 19 private ExpectationList myCreateCallExpectationParameter0Values = new ExpectationList("MockCallFactory.createCallExpectation(Callable) com.mockobjects.dynamic.Callable"); 20 private ExpectationCounter myCreateCallSignatureCalls = new ExpectationCounter("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable)"); 21 private ReturnValues myActualCreateCallSignatureReturnValues = new ReturnValues("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable)", true); 22 private ExpectationList myCreateCallSignatureParameter0Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) java.lang.String"); 23 private ExpectationList myCreateCallSignatureParameter1Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.ConstraintMatcher"); 24 private ExpectationList myCreateCallSignatureParameter2Values = new ExpectationList("MockCallFactory.createCallMatch(String, ConstraintMatcher, Callable) com.mockobjects.dynamic.Callable"); 25 26 public void setExpectedCreateReturnStubCalls(int calls){ 27 myCreateReturnStubCalls.setExpected(calls); 28 } 29 30 public void addExpectedCreateReturnStub(Object arg0){ 31 myCreateReturnStubParameter0Values.addExpected(arg0); 32 } 33 34 public Callable createReturnStub(Object arg0){ 35 myCreateReturnStubCalls.inc(); 36 myCreateReturnStubParameter0Values.addActual(arg0); 37 Object nextReturnValue = myActualCreateReturnStubReturnValues.getNext(); 38 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 39 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 40 return (Callable) nextReturnValue; 41 } 42 43 public void setupExceptionCreateReturnStub(Throwable arg){ 44 myActualCreateReturnStubReturnValues.add(new ExceptionalReturnValue(arg)); 45 } 46 47 public void setupCreateReturnStub(Callable arg){ 48 myActualCreateReturnStubReturnValues.add(arg); 49 } 50 51 public void setExpectedCreateThrowStubCalls(int calls){ 52 myCreateThrowStubCalls.setExpected(calls); 53 } 54 55 public void addExpectedCreateThrowStub(Throwable arg0){ 56 myCreateThrowStubParameter0Values.addExpected(arg0); 57 } 58 59 public Callable createThrowStub(Throwable arg0){ 60 myCreateThrowStubCalls.inc(); 61 myCreateThrowStubParameter0Values.addActual(arg0); 62 Object nextReturnValue = myActualCreateThrowStubReturnValues.getNext(); 63 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 64 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 65 return (Callable) nextReturnValue; 66 } 67 68 public void setupExceptionCreateThrowStub(Throwable arg){ 69 myActualCreateThrowStubReturnValues.add(new ExceptionalReturnValue(arg)); 70 } 71 72 public void setupCreateThrowStub(Callable arg){ 73 myActualCreateThrowStubReturnValues.add(arg); 74 } 75 76 public void setExpectedCreateVoidStubCalls(int calls){ 77 myCreateVoidStubCalls.setExpected(calls); 78 } 79 80 public Callable createVoidStub(){ 81 myCreateVoidStubCalls.inc(); 82 Object nextReturnValue = myActualCreateVoidStubReturnValues.getNext(); 83 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 84 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 85 return (Callable) nextReturnValue; 86 } 87 88 public void setupExceptionCreateVoidStub(Throwable arg){ 89 myActualCreateVoidStubReturnValues.add(new ExceptionalReturnValue(arg)); 90 } 91 92 public void setupCreateVoidStub(Callable arg){ 93 myActualCreateVoidStubReturnValues.add(arg); 94 } 95 96 public void setExpectedCreateCallExpectationCalls(int calls){ 97 myCreateCallExpectationCalls.setExpected(calls); 98 } 99 100 public void addExpectedCreateCallExpectation(Callable arg0){ 101 myCreateCallExpectationParameter0Values.addExpected(arg0); 102 } 103 104 public Callable createCallExpectation(Callable arg0){ 105 myCreateCallExpectationCalls.inc(); 106 myCreateCallExpectationParameter0Values.addActual(arg0); 107 Object nextReturnValue = myActualCreateCallExpectationReturnValues.getNext(); 108 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 109 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 110 return (Callable) nextReturnValue; 111 } 112 113 public void setupExceptionCreateCallExpectation(Throwable arg){ 114 myActualCreateCallExpectationReturnValues.add(new ExceptionalReturnValue(arg)); 115 } 116 117 public void setupCreateCallExpectation(Callable arg){ 118 myActualCreateCallExpectationReturnValues.add(arg); 119 } 120 121 public void setExpectedCreateCallSignatureCalls(int calls){ 122 myCreateCallSignatureCalls.setExpected(calls); 123 } 124 125 public void addExpectedCreateCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){ 126 myCreateCallSignatureParameter0Values.addExpected(arg0); 127 myCreateCallSignatureParameter1Values.addExpectedMany(arg1.getConstraints()); 128 myCreateCallSignatureParameter2Values.addExpected(arg2); 129 } 130 131 public Callable createCallSignature(String arg0, ConstraintMatcher arg1, Callable arg2){ 132 myCreateCallSignatureCalls.inc(); 133 myCreateCallSignatureParameter0Values.addActual(arg0); 134 myCreateCallSignatureParameter1Values.addActualMany(arg1.getConstraints()); 135 myCreateCallSignatureParameter2Values.addActual(arg2); 136 Object nextReturnValue = myActualCreateCallSignatureReturnValues.getNext(); 137 if (nextReturnValue instanceof ExceptionalReturnValue && ((ExceptionalReturnValue)nextReturnValue).getException() instanceof RuntimeException ) 138 throw (RuntimeException )((ExceptionalReturnValue)nextReturnValue).getException(); 139 return (Callable) nextReturnValue; 140 } 141 142 public void setupExceptionCreateCallSignature(Throwable arg){ 143 myActualCreateCallSignatureReturnValues.add(new ExceptionalReturnValue(arg)); 144 } 145 146 public void setupCreateCallSignature(Callable arg){ 147 myActualCreateCallSignatureReturnValues.add(arg); 148 } 149 150 public void verify(){ 151 myCreateReturnStubCalls.verify(); 152 myCreateReturnStubParameter0Values.verify(); 153 myCreateThrowStubCalls.verify(); 154 myCreateThrowStubParameter0Values.verify(); 155 myCreateVoidStubCalls.verify(); 156 myCreateCallExpectationCalls.verify(); 157 myCreateCallExpectationParameter0Values.verify(); 158 myCreateCallSignatureCalls.verify(); 159 myCreateCallSignatureParameter0Values.verify(); 160 myCreateCallSignatureParameter1Values.verify(); 161 myCreateCallSignatureParameter2Values.verify(); 162 } 163 } 164 | Popular Tags |