From: Steve F. <sm...@us...> - 2003-07-09 23:54:23
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv3011/src/core/com/mockobjects/dynamic Modified Files: CoreMock.java Mock.java Log Message: Tidied up Mock and CoreMock Reworked some of the tests to be more legible and simpler. Also, closer to mock implementation Index: CoreMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CoreMock.java 7 Jul 2003 01:17:57 -0000 1.5 +++ CoreMock.java 9 Jul 2003 23:54:20 -0000 1.6 @@ -12,15 +12,15 @@ private String name; public CoreMock(Class mockedClass, String name, CallableCollection callables) { + this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this); this.name = name; this.invocationMatchers = callables; - this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this); } public Object proxy() { return this.proxy; } - + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { @@ -62,17 +62,17 @@ invocationMatchers.addMatch(invocationMatcher); } - protected boolean isCheckingEqualityOnProxy(Invocation invocation) { + private boolean isCheckingEqualityOnProxy(Invocation invocation) { return (invocation.getMethodName().equals("equals")) && (invocation.args.length == 1) && (Proxy.isProxyClass(invocation.args[0].getClass())); } - protected boolean isMockNameGetter(Invocation invocation) { + private boolean isMockNameGetter(Invocation invocation) { return (invocation.getMethodName().equals("getMockName")) && (invocation.args.length == 0); } public void reset() { - this.invocationMatchers.reset(); + invocationMatchers.reset(); } public static String mockNameFromClass(Class c) { Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- Mock.java 7 Jul 2003 01:19:21 -0000 1.31 +++ Mock.java 9 Jul 2003 23:54:20 -0000 1.32 @@ -38,7 +38,36 @@ return C.args(C.eq(constraintArg)); } } - + + public void expect(String methodName, ConstraintMatcher args) { + coreMock.expect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args))); + } + + + public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) { + coreMock.expect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result))); + } + + public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) { + coreMock.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception))); + } + + public void match(String methodName, ConstraintMatcher args) { + coreMock.stub(callableFactory.createVoidCallable(methodName, args)); + } + + public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) { + coreMock.stub(callableFactory.createReturnCallable(methodName, args, result)); + } + + public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) { + coreMock.stub(callableFactory.createThrowableCallable(methodName, args, throwable)); + } + + /* + * --- Sugar methods ---- + */ + public void expect(String methodName) { expect(methodName, C.NO_ARGS); } @@ -47,56 +76,44 @@ expect(methodName, createConstraintMatcher(singleEqualArg)); } - public void expect(String methodName, ConstraintMatcher args) { - coreMock.expect(callableFactory.createCallExpectation(callableFactory.createVoidCallable(methodName, args))); - } - public void expectAndReturn(String methodName, Object result) { - this.expectAndReturn(methodName, C.NO_ARGS, result); + expectAndReturn(methodName, C.NO_ARGS, result); } public void expectAndReturn(String methodName, boolean result) { - this.expectAndReturn(methodName, new Boolean(result)); + expectAndReturn(methodName, new Boolean(result)); } public void expectAndReturn(String methodName, int result) { - this.expectAndReturn(methodName, new Integer(result)); + expectAndReturn(methodName, new Integer(result)); } public void expectAndReturn(String methodName, Object singleEqualArg, Object result) { - this.expectAndReturn(methodName, createConstraintMatcher(singleEqualArg), result); + expectAndReturn(methodName, createConstraintMatcher(singleEqualArg), result); } public void expectAndReturn(String methodName, Object singleEqualArg, boolean result) { - this.expectAndReturn(methodName, singleEqualArg, new Boolean(result)); + expectAndReturn(methodName, singleEqualArg, new Boolean(result)); } public void expectAndReturn(String methodName, Object singleEqualArg, int result) { - this.expectAndReturn(methodName, singleEqualArg, new Integer(result)); + expectAndReturn(methodName, singleEqualArg, new Integer(result)); } public void expectAndReturn(String methodName, ConstraintMatcher args, boolean result) { - this.expectAndReturn(methodName, args, new Boolean(result)); + expectAndReturn(methodName, args, new Boolean(result)); } public void expectAndReturn(String methodName, ConstraintMatcher args, int result) { - this.expectAndReturn(methodName, args, new Integer(result)); + expectAndReturn(methodName, args, new Integer(result)); } - public void expectAndReturn(String methodName, ConstraintMatcher args, Object result) { - coreMock.expect(callableFactory.createCallExpectation(callableFactory.createReturnCallable(methodName, args, result))); - } - public void expectAndThrow(String methodName, Throwable exception) { - this.expectAndThrow(methodName, C.NO_ARGS, exception); + expectAndThrow(methodName, C.NO_ARGS, exception); } public void expectAndThrow(String methodName, Object singleEqualArg, Throwable exception) { - this.expectAndThrow(methodName, createConstraintMatcher(singleEqualArg), exception); - } - - public void expectAndThrow(String methodName, ConstraintMatcher args, Throwable exception) { - coreMock.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, exception))); + expectAndThrow(methodName, createConstraintMatcher(singleEqualArg), exception); } public void match(String methodName) { @@ -115,74 +132,62 @@ match(methodName, new Boolean(singleEqualArg)); } - public void match(String methodName, ConstraintMatcher args) { - coreMock.stub(callableFactory.createVoidCallable(methodName, args)); - } - public void matchAndReturn(String methodName, Object result) { - this.matchAndReturn(methodName, C.NO_ARGS, result); + matchAndReturn(methodName, C.NO_ARGS, result); } public void matchAndReturn(String methodName, boolean result) { - this.matchAndReturn(methodName, new Boolean(result)); + matchAndReturn(methodName, new Boolean(result)); } public void matchAndReturn(String methodName, int result) { - this.matchAndReturn(methodName, new Integer(result)); + matchAndReturn(methodName, new Integer(result)); } public void matchAndReturn(String methodName, Object singleEqualArg, Object result) { - this.matchAndReturn(methodName, createConstraintMatcher(singleEqualArg), result); + matchAndReturn(methodName, createConstraintMatcher(singleEqualArg), result); } public void matchAndReturn(String methodName, boolean singleEqualArg, Object result) { - this.matchAndReturn(methodName, new Boolean(singleEqualArg), result); + matchAndReturn(methodName, new Boolean(singleEqualArg), result); } public void matchAndReturn(String methodName, int singleEqualArg, Object result) { - this.matchAndReturn(methodName, new Integer(singleEqualArg), result); + matchAndReturn(methodName, new Integer(singleEqualArg), result); } public void matchAndReturn(String methodName, Object singleEqualArg, boolean result) { - this.matchAndReturn(methodName, singleEqualArg, new Boolean(result)); + matchAndReturn(methodName, singleEqualArg, new Boolean(result)); } public void matchAndReturn(String methodName, Object singleEqualArg, int result) { - this.matchAndReturn(methodName, singleEqualArg, new Integer(result)); + matchAndReturn(methodName, singleEqualArg, new Integer(result)); } public void matchAndReturn(String methodName, ConstraintMatcher args, boolean result) { - this.matchAndReturn(methodName, args, new Boolean(result)); + matchAndReturn(methodName, args, new Boolean(result)); } public void matchAndReturn(String methodName, ConstraintMatcher args, int result) { - this.matchAndReturn(methodName, args, new Integer(result)); - } - - public void matchAndReturn(String methodName, ConstraintMatcher args, Object result) { - coreMock.stub(callableFactory.createReturnCallable(methodName, args, result)); + matchAndReturn(methodName, args, new Integer(result)); } public void matchAndThrow(String methodName, Throwable throwable) { - this.matchAndThrow(methodName, C.NO_ARGS, throwable); + matchAndThrow(methodName, C.NO_ARGS, throwable); } public void matchAndThrow(String methodName, Object singleEqualArg, Throwable throwable) { - this.matchAndThrow(methodName, createConstraintMatcher(singleEqualArg), throwable); + matchAndThrow(methodName, createConstraintMatcher(singleEqualArg), throwable); } public void matchAndThrow(String methodName, boolean singleEqualArg, Throwable throwable) { - this.matchAndThrow(methodName,new Boolean(singleEqualArg), throwable); + matchAndThrow(methodName,new Boolean(singleEqualArg), throwable); } public void matchAndThrow(String methodName, int singleEqualArg, Throwable throwable) { - this.matchAndThrow(methodName,new Integer(singleEqualArg), throwable); + matchAndThrow(methodName,new Integer(singleEqualArg), throwable); } - public void matchAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) { - coreMock.stub(callableFactory.createThrowableCallable(methodName, args, throwable)); - } - /** @deprecated @see OrderedMock */ public void expect(String methodName, CallSequence deprecated) { |