From: Steve F. <sm...@us...> - 2003-09-11 21:39:05
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory sc8-pr-cvs1:/tmp/cvs-serv7270/src/core/com/mockobjects/dynamic Modified Files: CoreMock.java InvocationDispatcher.java Mock.java Added Files: LIFOInvocationDispatcher.java InvokableFactory.java DefaultInvokableFactory.java Removed Files: CallBag.java CallableFactory.java DefaultCallFactory.java OrderedMock.java Log Message: Changed CoreMock to use InvocationDispatcher instead of CallableCollection, and propagated changes. Removed OrderedMock and other unused types. --- NEW FILE: LIFOInvocationDispatcher.java --- /* * Created on 20-Aug-2003 * Copyright mockobjects.com * */ package com.mockobjects.dynamic; import java.util.ArrayList; import java.util.Iterator; import java.util.ListIterator; import com.mockobjects.Verifiable; public class LIFOInvocationDispatcher implements InvocationDispatcher { private ArrayList invokables = new ArrayList(); public Object dispatch(Invocation invocation) throws Throwable { ListIterator i = invokables.listIterator(invokables.size()); while (i.hasPrevious()) { Invokable invokable = (Invokable)i.previous(); if (invokable.matches(invocation)) { return invokable.invoke(invocation); } } throw new DynamicMockError(invocation, "Nothing matches on this mock"); } public void add(Invokable invokable) { invokables.add(invokable); } public void verify() { Iterator i = invokables.iterator(); while (i.hasNext()) { ((Verifiable)i.next()).verify(); } } public void clear() { invokables.clear(); } } --- NEW FILE: InvokableFactory.java --- package com.mockobjects.dynamic; public interface InvokableFactory { Invokable createCallExpectation( Invokable invokable ); Invokable createReturnCallable( String methodName, ConstraintMatcher constraints, Object result ); Invokable createThrowableCallable( String methodName, ConstraintMatcher constraints, Throwable throwable); Invokable createVoidCallable( String methodName, ConstraintMatcher constraints); } --- NEW FILE: DefaultInvokableFactory.java --- package com.mockobjects.dynamic; public class DefaultInvokableFactory implements InvokableFactory { public Invokable createCallExpectation(Invokable callable) { return new CallOnceExpectation(callable); } public Invokable createReturnCallable(String methodName, ConstraintMatcher constraints, Object result) { return createCallSignature(methodName, constraints, createReturnStub(result)); } public Invokable createThrowableCallable(String methodName, ConstraintMatcher constraints, Throwable throwable) { return createCallSignature(methodName, constraints, createThrowStub(throwable)); } public Invokable createVoidCallable(String methodName, ConstraintMatcher constraints) { return createCallSignature(methodName, constraints, createVoidStub()); } private Invokable createCallSignature(String methodName, ConstraintMatcher constraints, Invokable callable) { return new CallSignature( methodName, constraints, callable ); } private Invokable createReturnStub(Object result) { return new ReturnStub(result); } private Invokable createThrowStub( Throwable exception ) { return new ThrowStub(exception); } private Invokable createVoidStub() { return new VoidStub(); } } Index: CoreMock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/CoreMock.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- CoreMock.java 20 Aug 2003 21:51:27 -0000 1.9 +++ CoreMock.java 11 Sep 2003 21:39:01 -0000 1.10 @@ -7,14 +7,14 @@ public class CoreMock implements DynamicMock { - private CallableCollection invocationMatchers; + private InvocationDispatcher invocationDispatcher; private Object proxy; private String name; - public CoreMock(Class mockedClass, String name, CallableCollection callables) { + public CoreMock(Class mockedClass, String name, InvocationDispatcher invocationDispatcher) { this.proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { mockedClass }, this); this.name = name; - this.invocationMatchers = callables; + this.invocationDispatcher = invocationDispatcher; // callables.addStub(new ProxyIsEqual(this.proxy)); } @@ -33,7 +33,7 @@ } else if (invocation.isMockNameGetter()) { return this.getMockName(); } else { - return invocationMatchers.invoke(invocation); + return invocationDispatcher.dispatch(invocation); } } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); @@ -42,7 +42,7 @@ public void verify() { try { - invocationMatchers.verify(); + invocationDispatcher.verify(); } catch (AssertionFailedError ex) { throw new AssertionFailedError(name + ": " + ex.getMessage()); } @@ -57,15 +57,15 @@ } public void expect(Invokable invocationMatcher) { - invocationMatchers.addExpect(invocationMatcher); + invocationDispatcher.add(invocationMatcher); } public void stub(Invokable invocationMatcher) { - invocationMatchers.addStub(invocationMatcher); + invocationDispatcher.add(invocationMatcher); } public void reset() { - invocationMatchers.reset(); + invocationDispatcher.clear(); } public static String mockNameFromClass(Class c) { Index: InvocationDispatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/InvocationDispatcher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- InvocationDispatcher.java 20 Aug 2003 22:38:40 -0000 1.2 +++ InvocationDispatcher.java 11 Sep 2003 21:39:01 -0000 1.3 @@ -1,44 +1,14 @@ /* - * Created on 20-Aug-2003 + * 11-Sep-2003 * Copyright mockobjects.com - * + * */ package com.mockobjects.dynamic; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ListIterator; - import com.mockobjects.Verifiable; -public class InvocationDispatcher implements Verifiable { - - private ArrayList invokables = new ArrayList(); - - public Object dispatch(Invocation invocation) throws Throwable { - ListIterator i = invokables.listIterator(invokables.size()); - while (i.hasPrevious()) { - Invokable invokable = (Invokable)i.previous(); - if (invokable.matches(invocation)) { - return invokable.invoke(invocation); - } - } - throw new DynamicMockError(invocation, "Nothing matches on this mock"); - } - - public void add(Invokable invokable) { - invokables.add(invokable); - } - - public void verify() { - Iterator i = invokables.iterator(); - while (i.hasNext()) { - ((Verifiable)i.next()).verify(); - } - } - - public void clear() { - invokables.clear(); - } - -} +public interface InvocationDispatcher extends Verifiable { + Object dispatch(Invocation invocation) throws Throwable; + void add(Invokable invokable); + void clear(); +} \ No newline at end of file Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Mock.java 9 Aug 2003 13:17:48 -0000 1.33 +++ Mock.java 11 Sep 2003 21:39:01 -0000 1.34 @@ -6,17 +6,17 @@ import com.mockobjects.constraint.Constraint; public class Mock implements Verifiable { - private CallableFactory callableFactory; + private InvokableFactory callableFactory; private DynamicMock coreMock; - public Mock(CallableFactory callableFactory, CallableCollection callables, Class mockedClass, String name) { - coreMock = new CoreMock(mockedClass, name, callables); + public Mock(InvokableFactory callableFactory, InvocationDispatcher invocationDispatcher, Class mockedClass, String name) { + coreMock = new CoreMock(mockedClass, name, invocationDispatcher); this.callableFactory = callableFactory; } public Mock(Class mockedClass, String nonDefaultName) { - this(new DefaultCallFactory(), new CallBag(), mockedClass, nonDefaultName); + this(new DefaultInvokableFactory(), new LIFOInvocationDispatcher(), mockedClass, nonDefaultName); } public Mock(Class mockedClass) { @@ -47,8 +47,8 @@ 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 expectAndThrow(String methodName, ConstraintMatcher args, Throwable throwable) { + coreMock.expect(callableFactory.createCallExpectation(callableFactory.createThrowableCallable(methodName, args, throwable))); } public void match(String methodName, ConstraintMatcher args) { --- CallBag.java DELETED --- --- CallableFactory.java DELETED --- --- DefaultCallFactory.java DELETED --- --- OrderedMock.java DELETED --- |