jmock-1.2.0.orig/0000755000175000017500000000000011636534756012340 5ustar tonytonyjmock-1.2.0.orig/jmock-cglib/0000755000175000017500000000000011636534756014521 5ustar tonytonyjmock-1.2.0.orig/jmock-cglib/LICENSE.txt0000644000175000017500000000266307762452754016355 0ustar tonytonyCopyright (c) 2000-2003, jMock.org All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of jMock nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jmock-1.2.0.orig/jmock-cglib/META-INF/0000755000175000017500000000000010607017650015643 5ustar tonytonyjmock-1.2.0.orig/jmock-cglib/META-INF/MANIFEST.MF0000644000175000017500000000015210607017646017300 0ustar tonytonyManifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: 1.5.0_08-b03 (Sun Microsystems Inc.) jmock-1.2.0.orig/jmock-cglib/org/0000755000175000017500000000000010607017644015275 5ustar tonytonyjmock-1.2.0.orig/jmock-cglib/org/jmock/0000755000175000017500000000000010607017646016402 5ustar tonytonyjmock-1.2.0.orig/jmock-cglib/org/jmock/cglib/0000755000175000017500000000000010607017646017462 5ustar tonytonyjmock-1.2.0.orig/jmock-cglib/org/jmock/cglib/MockObjectTestCase.java0000644000175000017500000000256010605540412023772 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.cglib; import org.jmock.Mock; import org.jmock.core.DynamicMock; public abstract class MockObjectTestCase extends org.jmock.MockObjectTestCase { protected MockObjectTestCase(String testName) { super(testName); } protected MockObjectTestCase() { } public Mock mock(Class mockedClass, String roleName, Class[] constructorArgumentTypes, Object[] constructorArguments) { Mock newMock = new Mock(newCoreMock(mockedClass, roleName, constructorArgumentTypes, constructorArguments)); registerToVerify(newMock); return newMock; } public Mock mock(Class mockedClass, Class[] constructorArgumentTypes, Object[] constructorArguments) { return mock(mockedClass, defaultMockNameForType(mockedClass), constructorArgumentTypes, constructorArguments); } protected DynamicMock newCoreMock( Class mockedType, String roleName ) { return new CGLIBCoreMock(mockedType, roleName); } protected DynamicMock newCoreMock( Class mockedClass, String roleName, Class[] constructorArgumentTypes, Object[] constructorArguments) { return new CGLIBCoreMock(mockedClass, roleName, constructorArgumentTypes, constructorArguments); } } jmock-1.2.0.orig/jmock-cglib/org/jmock/cglib/CGLIBCoreMock.java0000644000175000017500000000557710606735326022607 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.cglib; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import junit.framework.AssertionFailedError; import net.sf.cglib.core.DefaultNamingPolicy; import net.sf.cglib.core.NamingPolicy; import net.sf.cglib.core.Predicate; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; import org.jmock.core.AbstractDynamicMock; import org.jmock.core.Invocation; import org.jmock.core.InvocationDispatcher; import org.jmock.core.LIFOInvocationDispatcher; public class CGLIBCoreMock extends AbstractDynamicMock implements MethodInterceptor { private static NamingPolicy NAMING_POLICY = new DefaultNamingPolicy() { public String getClassName(String prefix, String source, Object key, Predicate names) { return "org.jmock.codegen." + super.getClassName(prefix, source, key, names); } }; private Object proxy = null; public CGLIBCoreMock(Class mockedType, String name) { this(mockedType, name, new LIFOInvocationDispatcher()); } public CGLIBCoreMock(Class mockedType, String name, Class[] constructorArgumentTypes, Object[] constructorArguments) { this(mockedType, name, constructorArgumentTypes, constructorArguments, new LIFOInvocationDispatcher()); } public CGLIBCoreMock(Class mockedType, String name, InvocationDispatcher invocationDispatcher) { this(mockedType, name, new Class[0], new Object[0], invocationDispatcher); } public CGLIBCoreMock(Class mockedType, String name, Class[] constructorArgumentTypes, Object[] constructorArguments, InvocationDispatcher invocationDispatcher) { super(mockedType, name, invocationDispatcher); checkIsNotNonStaticInnerClass(mockedType); Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(mockedType.getClassLoader()); enhancer.setSuperclass(mockedType); enhancer.setCallback(this); enhancer.setNamingPolicy(NAMING_POLICY); this.proxy = enhancer.create(constructorArgumentTypes, constructorArguments); } private void checkIsNotNonStaticInnerClass(Class mockedType) { if (mockedType.getDeclaringClass() != null && !Modifier.isStatic(mockedType.getModifiers())) { throw new AssertionFailedError("cannot mock non-static inner class " + mockedType.getName()); } } public Object proxy() { return this.proxy; } public Object intercept(Object thisProxy, Method method, Object[] args, MethodProxy superProxy) throws Throwable { return proxy == null ? superProxy.invokeSuper(thisProxy, args) : mockInvocation(new Invocation(proxy, method, args)); } }jmock-1.2.0.orig/jmock-core/0000755000175000017500000000000011636534756014371 5ustar tonytonyjmock-1.2.0.orig/jmock-core/LICENSE.txt0000644000175000017500000000266307762452754016225 0ustar tonytonyCopyright (c) 2000-2003, jMock.org All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of jMock nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jmock-1.2.0.orig/jmock-core/META-INF/0000755000175000017500000000000010607017650015513 5ustar tonytonyjmock-1.2.0.orig/jmock-core/META-INF/MANIFEST.MF0000644000175000017500000000015210607017646017150 0ustar tonytonyManifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: 1.5.0_08-b03 (Sun Microsystems Inc.) jmock-1.2.0.orig/jmock-core/org/0000755000175000017500000000000010607017644015145 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/0000755000175000017500000000000010607017646016252 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/util/0000755000175000017500000000000010607017646017227 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/util/Verifier.java0000644000175000017500000000526410605540406021645 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.util; import java.lang.reflect.Field; import java.util.Vector; import junit.framework.Assert; import org.jmock.core.Verifiable; /** * Helper class to verify all {@link org.jmock.core.Verifiable} fields of an object. *

Example usage:

* Verifying all expectations on one object at a time:

*

 * public class MockX implements Verifiable {
 *    private Expectation... anExpectation = new Expectation...(...);
 *    private Expectation... aSecondExpectation = new Expectation...(...);
 * 

* public void verify() { * Verifier.verifyObject(this); * } * } *

* This example shows how most mock objects implement * {@link org.jmock.core.Verifiable Verifiable} by delegation. * * @version $Id: Verifier.java,v 1.1 2007/04/06 13:52:06 npryce Exp $ * @see org.jmock.core.Verifiable * @since 1.0 */ public class Verifier { private static Vector myProcessingObjects = new Vector(); /** * Verifies all the fields of type Verifiable in the given object, including * those inherited from superclasses. * * @param anObject The object to be verified. */ static synchronized public void verifyObject( Object anObject ) { verifyFieldsForClass(anObject, anObject.getClass(), myProcessingObjects); } static private void verifyFieldsForClass( Object anObject, Class aClass, Vector alreadyProcessed ) { if (alreadyProcessed.contains(anObject) || isBaseObjectClass(aClass)) { return; } verifyFieldsForClass(anObject, aClass.getSuperclass(), alreadyProcessed); try { alreadyProcessed.addElement(anObject); Field[] fields = aClass.getDeclaredFields(); for (int i = 0; i < fields.length; ++i) { verifyField(fields[i], anObject, alreadyProcessed); } } finally { alreadyProcessed.removeElement(anObject); } } static private void verifyField( Field aField, Object anObject, Vector alreadyProcessed ) { try { aField.setAccessible(true); Object fieldObject = aField.get(anObject); if (isVerifiable(fieldObject) && !alreadyProcessed.contains(fieldObject)) { ((Verifiable)fieldObject).verify(); } } catch (IllegalAccessException e) { Assert.fail("Could not access field " + aField.getName()); } } private static boolean isVerifiable( Object anObject ) { return anObject instanceof Verifiable; } private static boolean isBaseObjectClass( Class aClass ) { return aClass.equals(Object.class); } } jmock-1.2.0.orig/jmock-core/org/jmock/util/Dummy.java0000644000175000017500000000341510606776010021164 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.util; import org.jmock.core.CoreMock; import org.jmock.core.Formatting; import org.jmock.core.Invocation; import org.jmock.core.InvocationMocker; import org.jmock.core.matcher.StatelessInvocationMatcher; import org.jmock.core.stub.CustomStub; /** * @since 1.0 * * @deprecated Use MockObjectTestCase.newDummy instead */ public class Dummy { private Dummy() { /* This class cannot be instantiated. */ } public static Object newDummy( Class interfaceClass ) { return newDummy(interfaceClass, "dummy" + Formatting.classShortName(interfaceClass)); } public static Object newDummy( final Class interfaceClass, final String name ) { CoreMock mock = new CoreMock(interfaceClass, name); InvocationMocker mocker = new InvocationMocker(); mocker.addMatcher(new StatelessInvocationMatcher() { public boolean matches( Invocation invocation ) { return invocation.invokedMethod.getDeclaringClass() == interfaceClass; } public StringBuffer describeTo( StringBuffer buf ) { return buf.append("any invokedMethod declared in " + interfaceClass); } }); mocker.setStub(new CustomStub("dummy invokedMethod") { public Object invoke( Invocation invocation ) throws Throwable { throw new NotImplementedException(invocation.invokedMethod.getName() + " called on " + name); } }); mock.addInvokable(mocker); return mock.proxy(); } public static Object newDummy( final String name ) { return new Object() { public String toString() { return name; } }; } } jmock-1.2.0.orig/jmock-core/org/jmock/util/PropertyUtil.java0000644000175000017500000000233210605540406022545 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.util; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; /** * Utility class for accessing properties on JavaBean objects. * * See http://java.sun.com/products/javabeans/docs/index.html for * more information on JavaBeans. * * @author Iain McGinniss * @since 1.1.0 */ public class PropertyUtil { /** * Returns the description of the property with the provided * name on the provided object's interface. * @return the description of the property, or null if the * property does not exist. * * @throws IntrospectionException if an error occured using * the JavaBean Introspector class to query the properties * of the provided class. */ public static PropertyDescriptor getPropertyDescriptor(String propertyName, Object fromObj) throws IntrospectionException { BeanInfo beanInfo = Introspector.getBeanInfo(fromObj.getClass()); PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); for(int i=0; i < properties.length; i++) { if(properties[i].getName().equals(propertyName)) { return properties[i]; } } return null; } } jmock-1.2.0.orig/jmock-core/org/jmock/util/NotImplementedException.java0000644000175000017500000000103410605540406024664 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.util; /** * @since 1.0 */ public class NotImplementedException extends RuntimeException { private static final long serialVersionUID = 1L; /** * NotImplementedException constructor comment. */ public NotImplementedException() { super(); } /** * NotImplementedException constructor comment. * * @param message java.lang.String */ public NotImplementedException( String message ) { super(message); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/0000755000175000017500000000000010607017646017202 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/core/InvocationDispatcher.java0000644000175000017500000000052710605540374024166 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * @since 1.0 */ public interface InvocationDispatcher extends Verifiable, SelfDescribing { Object dispatch( Invocation invocation ) throws Throwable; void setDefaultStub( Stub newDefaultStub ); void add( Invokable invokable ); void clear(); } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/0000755000175000017500000000000010607017646020157 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/core/stub/ReturnIteratorStub.java0000644000175000017500000000177010605540400024641 0ustar tonytonypackage org.jmock.core.stub; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import org.jmock.core.Formatting; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class ReturnIteratorStub implements Stub { private Collection collection; public ReturnIteratorStub(Collection collection) { this.collection = collection; } public ReturnIteratorStub(Object[] array) { this.collection = Arrays.asList(array); } public Object invoke(Invocation invocation) throws Throwable { return collection.iterator(); } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("return iterator over "); boolean separate = false; for (Iterator i = collection.iterator(); i.hasNext();) { if (separate) buffer.append(", "); buffer.append(Formatting.toReadableString(i.next())); separate = true; } return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/ThrowStub.java0000644000175000017500000000347010605540400022752 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import junit.framework.Assert; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class ThrowStub extends Assert implements Stub { private Throwable throwable; public ThrowStub(Throwable throwable) { this.throwable = throwable; } public Object invoke(Invocation invocation) throws Throwable { if (isThrowingCheckedException()) { checkTypeCompatiblity(invocation.invokedMethod.getExceptionTypes()); } throwable.fillInStackTrace(); throw throwable; } public StringBuffer describeTo(StringBuffer buffer) { return buffer.append("throws <").append(throwable).append(">"); } private void checkTypeCompatiblity(Class[] allowedExceptionTypes) { for (int i = 0; i < allowedExceptionTypes.length; i++) { if (allowedExceptionTypes[i].isInstance(throwable)) return; } reportIncompatibleCheckedException(allowedExceptionTypes); } private void reportIncompatibleCheckedException(Class[] allowedTypes) { StringBuffer message = new StringBuffer(); message.append("tried to throw a "); message.append(throwable.getClass().getName()); message.append(" from a method that throws "); if (allowedTypes.length == 0) { message.append("no exceptions"); } else { for (int i = 0; i < allowedTypes.length; i++) { if (i > 0) message.append(","); message.append(allowedTypes[i].getName()); } } fail(message.toString()); } private boolean isThrowingCheckedException() { return !(throwable instanceof RuntimeException || throwable instanceof Error); } }jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/DefaultResultStub.java0000644000175000017500000000630010605540400024425 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import java.lang.reflect.Array; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import junit.framework.AssertionFailedError; import org.jmock.core.CoreMock; import org.jmock.core.Formatting; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class DefaultResultStub implements Stub { private Map resultValuesByType = new HashMap(); public DefaultResultStub() { createDefaultResults(); } public StringBuffer describeTo( StringBuffer buf ) { return buf.append("returns a default value"); } public void addResult( Class resultType, Object resultValue ) { resultValuesByType.put(resultType, resultValue); } public Object invoke( Invocation invocation ) throws Throwable { Class returnType = invocation.invokedMethod.getReturnType(); if (resultValuesByType.containsKey(returnType)) { return resultValuesByType.get(returnType); } else if (returnType.isArray()) { return Array.newInstance(returnType.getComponentType(), 0); } else if (returnType.isInterface()) { CoreMock nullMock = new CoreMock(returnType, "null" + Formatting.classShortName(returnType)); nullMock.setDefaultStub(this); return nullMock.proxy(); } else { throw new AssertionFailedError(createErrorMessage(invocation)); } } public String createErrorMessage( Invocation call ) { StringBuffer buf = new StringBuffer(); buf.append("unexpected result type: "); buf.append(call.invokedMethod.getReturnType().toString()); buf.append("\n"); if (resultValuesByType.isEmpty()) { buf.append("no result types are registered!"); } else { buf.append("expected one of: "); Iterator i = resultValuesByType.keySet().iterator(); boolean separatorRequired = false; while (i.hasNext()) { if (separatorRequired) buf.append(", "); buf.append(((Class)i.next()).getName()); separatorRequired = true; } } return buf.toString(); } protected void createDefaultResults() { addResult(boolean.class, Boolean.FALSE); addResult(void.class, null); addResult(byte.class, new Byte((byte)0)); addResult(short.class, new Short((short)0)); addResult(int.class, new Integer(0)); addResult(long.class, new Long(0L)); addResult(char.class, new Character('\0')); addResult(float.class, new Float(0.0F)); addResult(double.class, new Double(0.0)); addResult(Boolean.class, Boolean.FALSE); addResult(Byte.class, new Byte((byte)0)); addResult(Short.class, new Short((short)0)); addResult(Integer.class, new Integer(0)); addResult(Long.class, new Long(0L)); addResult(Character.class, new Character('\0')); addResult(Float.class, new Float(0.0F)); addResult(Double.class, new Double(0.0)); addResult(String.class, ""); addResult(Object.class, new Object()); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/CustomStub.java0000644000175000017500000000156110605540400023120 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import org.jmock.core.Stub; /** * A partial implementation of the Stub interface that makes it convenient to implement * application-specific stubs with inline anonymous classes: *
 * final String name = "NAME";
 * final StringBuffer buffer = new StringBuffer();
 * 

* mock.expect("describeTo", C.args(C.same(buffer))), new CustomStub("appends name to buffer") { * public Object invoke( Invocation invocation ) throws Throwable { * return buffer.append(name); * } * } ); *

*/ public abstract class CustomStub implements Stub { private String description; public CustomStub( String description ) { this.description = description; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append(description); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/VoidStub.java0000644000175000017500000000066610605540400022554 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class VoidStub implements Stub { public static final VoidStub INSTANCE = new VoidStub(); public Object invoke(Invocation invocation) throws Throwable { return null; } public StringBuffer describeTo(StringBuffer buffer) { return buffer.append("is void"); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/DoAllStub.java0000644000175000017500000000143010605540400022634 0ustar tonytonypackage org.jmock.core.stub; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class DoAllStub implements Stub { private final Stub[] stubs; public DoAllStub(Stub[] stubs) { this.stubs = (Stub[]) stubs.clone(); } public Object invoke(Invocation invocation) throws Throwable { Object result = null; for (int i = 0; i < stubs.length; i++) { result = stubs[i].invoke(invocation); } return result; } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("do all of "); for (int i = 0; i < stubs.length; i++) { if (i > 0) buffer.append(", "); stubs[i].describeTo(buffer); } return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/StubSequence.java0000644000175000017500000000201710605540400023413 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import junit.framework.AssertionFailedError; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class StubSequence implements Stub { List stubs; Iterator iterator; public StubSequence( Stub[] stubs ) { this.stubs = new ArrayList(Arrays.asList(stubs)); this.iterator = this.stubs.iterator(); } public Object invoke( Invocation invocation ) throws Throwable { if (iterator.hasNext()) { return ((Stub)iterator.next()).invoke(invocation); } throw new AssertionFailedError("no more stubs available"); } public StringBuffer describeTo( StringBuffer buffer ) { for (int i = 0; i < stubs.size(); i++) { if (i > 0) buffer.append(", and then "); ((Stub)stubs.get(i)).describeTo(buffer); } return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/TestFailureStub.java0000644000175000017500000000117610605540400024077 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import junit.framework.AssertionFailedError; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class TestFailureStub implements Stub { String errorMessage; public TestFailureStub( String errorMessage ) { this.errorMessage = errorMessage; } public Object invoke( Invocation invocation ) throws Throwable { throw new AssertionFailedError(errorMessage); } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("fails the test and reports \"" + errorMessage + "\""); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/ReturnStub.java0000644000175000017500000000110510605540400023117 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.stub; import org.jmock.core.Formatting; import org.jmock.core.Invocation; import org.jmock.core.Stub; public class ReturnStub implements Stub { private Object result; public ReturnStub(Object result) { this.result = result; } public Object invoke(Invocation invocation) throws Throwable { return result; } public StringBuffer describeTo(StringBuffer buffer) { return buffer.append("returns ").append( Formatting.toReadableString(result)); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/0000755000175000017500000000000010607017646020625 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokeAtMostOnceMatcher.java0000644000175000017500000000107710605540412026157 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import org.jmock.core.Invocation; /** * @since 1.1.0 */ public class InvokeAtMostOnceMatcher extends InvokedRecorder { public boolean matches( Invocation invocation ) { return !hasBeenInvoked(); } public boolean hasDescription() { return true; } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("expected at most once"); if (hasBeenInvoked()) buffer.append(" and has been invoked"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokedRecorder.java0000644000175000017500000000241710605540412024547 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import junit.framework.Assert; import org.jmock.core.Invocation; import org.jmock.core.InvocationMatcher; public class InvokedRecorder implements InvocationMatcher { private int invocationCount = 0; public int getInvocationCount() { return invocationCount; } public boolean hasBeenInvoked() { return invocationCount > 0; } public boolean matches( Invocation invocation ) { return true; } public void invoked( Invocation invocation ) { invocationCount++; } public boolean hasDescription() { return false; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer; } public void verify() { // always verifies } public void verifyHasBeenInvoked() { Assert.assertTrue("expected method was not invoked", hasBeenInvoked() ); } public void verifyHasBeenInvokedExactly( int expectedCount ) { Assert.assertTrue("expected method was not invoked the expected number of times: expected " + expectedCount + " times, was invoked " + invocationCount + " times", invocationCount == expectedCount ); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokeOnceMatcher.java0000644000175000017500000000113410605540412025021 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import org.jmock.core.Invocation; public class InvokeOnceMatcher extends InvokedRecorder { public boolean matches( Invocation invocation ) { return !hasBeenInvoked(); } public void verify() { verifyHasBeenInvoked(); } public boolean hasDescription() { return true; } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("expected once"); if (hasBeenInvoked()) buffer.append(" and has been invoked"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/NoArgumentsMatcher.java0000644000175000017500000000075310605540412025231 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import org.jmock.core.Invocation; public class NoArgumentsMatcher extends StatelessInvocationMatcher { public static final NoArgumentsMatcher INSTANCE = new NoArgumentsMatcher(); public boolean matches( Invocation invocation ) { return invocation.parameterValues.isEmpty(); } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("(no arguments)"); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/StatelessInvocationMatcher.java0000644000175000017500000000076110605540412026767 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import org.jmock.core.Invocation; import org.jmock.core.InvocationMatcher; public abstract class StatelessInvocationMatcher implements InvocationMatcher { public void invoked( Invocation invocation ) { // Do nothing because state cannot change } public void verify() { // Nothing to verify because state cannot change } public boolean hasDescription() { return true; } }jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/MethodNameMatcher.java0000644000175000017500000000167410605540412025013 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import org.jmock.core.Constraint; import org.jmock.core.Invocation; public class MethodNameMatcher extends StatelessInvocationMatcher { private Constraint constraint; public MethodNameMatcher( Constraint constraint ) { this.constraint = constraint; } public MethodNameMatcher( final String methodName ) { this(new Constraint() { public boolean eval( Object o ) { return methodName.equals(o); } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append(methodName); } }); } public boolean matches( Invocation invocation ) { return constraint.eval(invocation.invokedMethod.getName()); } public StringBuffer describeTo( StringBuffer buffer ) { return constraint.describeTo(buffer); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/TestFailureMatcher.java0000644000175000017500000000150510605540412025212 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import junit.framework.AssertionFailedError; import org.jmock.core.Invocation; import org.jmock.core.InvocationMatcher; public class TestFailureMatcher implements InvocationMatcher { private String errorMessage; public TestFailureMatcher( String errorMessage ) { this.errorMessage = errorMessage; } public boolean matches( Invocation invocation ) { return true; } public boolean hasDescription() { return true; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append(errorMessage); } public void invoked( Invocation invocation ) { throw new AssertionFailedError(errorMessage); } public void verify() { // Always verify } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokeAtLeastOnceMatcher.java0000644000175000017500000000100210605540412026271 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; public class InvokeAtLeastOnceMatcher extends InvokedRecorder { public void verify() { verifyHasBeenInvoked(); } public boolean hasDescription() { return true; } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("expected at least once"); if (hasBeenInvoked()) { buffer.append(" and has been invoked"); } return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokedAfterMatcher.java0000644000175000017500000000230310605540412025341 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import junit.framework.AssertionFailedError; import org.jmock.core.Invocation; public class InvokedAfterMatcher extends StatelessInvocationMatcher { private InvokedRecorder priorCallRecorder; private String priorCallDescription; public InvokedAfterMatcher( InvokedRecorder priorCallRecorder, String priorCallDescription ) { this.priorCallRecorder = priorCallRecorder; this.priorCallDescription = priorCallDescription; } public boolean matches( Invocation invocation ) { return priorCallRecorder.hasBeenInvoked(); } public void invoked( Invocation invocation ) { if (!matches(invocation)) { throw new AssertionFailedError("called out of order; should be called after " + priorCallDescription); } } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("after ").append(priorCallDescription); if( priorCallRecorder.hasBeenInvoked() ) { buffer.append(" (invoked)"); } else { buffer.append(" (not invoked)"); } return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/AnyArgumentsMatcher.java0000644000175000017500000000071710605540412025404 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import org.jmock.core.Invocation; public class AnyArgumentsMatcher extends StatelessInvocationMatcher { public static final AnyArgumentsMatcher INSTANCE = new AnyArgumentsMatcher(); public boolean matches( Invocation invocation ) { return true; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("(any arguments)"); } }jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokeCountMatcher.java0000644000175000017500000000146710605540412025236 0ustar tonytonypackage org.jmock.core.matcher; import org.jmock.core.Invocation; public class InvokeCountMatcher extends InvokedRecorder { private int expectedCount; public InvokeCountMatcher( int expectedCount ) { this.expectedCount = expectedCount; } public boolean matches( Invocation invocation ) { return getInvocationCount() < expectedCount; } public void verify() { verifyHasBeenInvokedExactly(expectedCount); } public boolean hasDescription() { return true; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("expected ") .append(expectedCount) .append(" times, invoked ") .append(getInvocationCount()) .append(" times"); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/ArgumentsMatcher.java0000644000175000017500000000221410605540412024726 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.matcher; import java.util.List; import org.jmock.core.Constraint; import org.jmock.core.Invocation; public class ArgumentsMatcher extends StatelessInvocationMatcher { private Constraint[] constraints; public ArgumentsMatcher( Constraint[] constraints ) { ArgumentsMatcher.this.constraints = (Constraint[])constraints.clone(); } public boolean matches( Invocation invocation ) { return constraints.length == invocation.parameterValues.size() && matchesValues(invocation.parameterValues); } private boolean matchesValues( List list ) { for (int i = 0; i < constraints.length; ++i) { if (!constraints[i].eval(list.get(i))) { return false; } } return true; } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("( "); for (int i = 0; i < constraints.length; i++) { if (i > 0) buffer.append(", "); constraints[i].describeTo(buffer); } buffer.append(" )"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/InvocationMocker.java0000644000175000017500000000637010605540374023322 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import junit.framework.AssertionFailedError; import org.jmock.core.stub.VoidStub; /** * @since 1.0 */ public class InvocationMocker implements Invokable, StubMatchersCollection { public interface Describer { public boolean hasDescription(); public void describeTo( StringBuffer buffer, List matchers, Stub stub, String name ); } private String name = null; private List matchers = new ArrayList(); private Stub stub = VoidStub.INSTANCE; private Describer describer; public InvocationMocker() { this(DEFAULT_DESCRIBER); } public InvocationMocker( Describer describer ) { this.describer = describer; } public boolean matches( Invocation invocation ) { Iterator i = matchers.iterator(); while (i.hasNext()) { if (!((InvocationMatcher)i.next()).matches(invocation)) { return false; } } return true; } public Object invoke( Invocation invocation ) throws Throwable { Iterator i = matchers.iterator(); while (i.hasNext()) { ((InvocationMatcher)i.next()).invoked(invocation); } return stub.invoke(invocation); } public void verify() { try { Iterator i = matchers.iterator(); while (i.hasNext()) { ((InvocationMatcher)i.next()).verify(); } } catch (AssertionFailedError error) { AssertionFailedError newError = new AssertionFailedError(error.getMessage() + "\n" + toString()); newError.fillInStackTrace(); throw newError; } } public void setName( String name ) { this.name = name; } public void addMatcher( InvocationMatcher matcher ) { matchers.add(matcher); } public void setStub( Stub stub ) { this.stub = stub; } public String toString() { return describeTo(new StringBuffer()).toString(); } public boolean hasDescription() { return describer.hasDescription(); } public StringBuffer describeTo( StringBuffer buffer ) { describer.describeTo(buffer, Collections.unmodifiableList(matchers), stub, name); return buffer; } public static final Describer DEFAULT_DESCRIBER = new Describer() { public boolean hasDescription() { return true; } public void describeTo( StringBuffer buffer, List matchers, Stub stub, String name ) { Iterator it = matchers.iterator(); while (it.hasNext()) { InvocationMatcher matcher = (InvocationMatcher)it.next(); if (matcher.hasDescription()) { matcher.describeTo(buffer).append(", "); } } stub.describeTo(buffer); if (name != null) { buffer.append(" [").append(name).append("]"); } } }; } jmock-1.2.0.orig/jmock-core/org/jmock/core/Invokable.java0000644000175000017500000000045310605540374021756 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * @since 1.0 */ public interface Invokable extends Verifiable, SelfDescribing { boolean matches( Invocation invocation ); Object invoke( Invocation invocation ) throws Throwable; boolean hasDescription(); } jmock-1.2.0.orig/jmock-core/org/jmock/core/DynamicMockError.java0000644000175000017500000000226410605540374023256 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import junit.framework.AssertionFailedError; /** * @since 1.0 */ public class DynamicMockError extends AssertionFailedError { private static final long serialVersionUID = 1L; public final DynamicMock dynamicMock; public final Invocation invocation; public final InvocationDispatcher dispatcher; public DynamicMockError( DynamicMock dynamicMock, Invocation invocation, InvocationDispatcher dispatcher, String message ) { super(message); this.dynamicMock = dynamicMock; this.invocation = invocation; this.dispatcher = dispatcher; } public StringBuffer writeTo( StringBuffer buffer ) { buffer.append(dynamicMock.toString()).append(": ") .append(super.getMessage()).append("\n"); buffer.append("Invoked: "); invocation.describeTo(buffer); buffer.append("\n"); buffer.append("Allowed:\n"); dispatcher.describeTo(buffer); return buffer; } public String getMessage() { return writeTo(new StringBuffer()).toString(); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/AbstractInvocationDispatcher.java0000644000175000017500000000417110605540374025651 0ustar tonytonypackage org.jmock.core; import java.util.Iterator; import java.util.ArrayList; import java.util.List; import org.jmock.core.stub.TestFailureStub; public abstract class AbstractInvocationDispatcher implements InvocationDispatcher { public static final String NO_EXPECTATIONS_MESSAGE = "No expectations set"; protected List invokables = new ArrayList(); protected Stub defaultStub = new TestFailureStub("unexpected invocation"); public void setDefaultStub( Stub defaultStub ) { this.defaultStub = defaultStub; } 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 StringBuffer describeTo( StringBuffer buffer ) { if (anyInvokableHasDescription()) { writeInvokablesTo(buffer); } else { buffer.append(NO_EXPECTATIONS_MESSAGE); } return buffer; } private void writeInvokablesTo( StringBuffer buffer ) { Iterator iterator = invokables.iterator(); while (iterator.hasNext()) { Invokable invokable = (Invokable)iterator.next(); if (invokable.hasDescription()) { invokable.describeTo(buffer).append("\n"); } } } private boolean anyInvokableHasDescription() { Iterator iterator = invokables.iterator(); while (iterator.hasNext()) { if (((Invokable)iterator.next()).hasDescription()) return true; } return false; } public Object dispatch( Invocation invocation ) throws Throwable { Iterator i = dispatchOrder(invokables); while (i.hasNext()) { Invokable invokable = (Invokable)i.next(); if (invokable.matches(invocation)) { return invokable.invoke(invocation); } } return defaultStub.invoke(invocation); } protected abstract Iterator dispatchOrder( List invokablesList ); } jmock-1.2.0.orig/jmock-core/org/jmock/core/Stub.java0000644000175000017500000000153210605540374020760 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * An object that stubs the behaviour of a invokedMethod invocation on behalf of an * {@link org.jmock.core.Invokable} object. * @since 1.0 */ public interface Stub extends SelfDescribing { /** * Processes the invocation. * * @param invocation The invocation to stub. * @return The result of the invocation, if not throwing an exception. * Must return null if the invocation is of a invokedMethod with a void return type. * @throws Throwable An exception to be thrown to the caller, if not returning a value. A checked exception * thrown from this invokedMethod must be in the throws list of the invoked method. */ Object invoke( Invocation invocation ) throws Throwable; } jmock-1.2.0.orig/jmock-core/org/jmock/core/AbstractDynamicMock.java0000644000175000017500000001307610606773326023741 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.lang.reflect.Method; import java.util.List; import junit.framework.AssertionFailedError; import org.jmock.core.constraint.IsAnything; import org.jmock.core.matcher.ArgumentsMatcher; import org.jmock.core.matcher.MethodNameMatcher; import org.jmock.core.matcher.NoArgumentsMatcher; import org.jmock.core.stub.CustomStub; import org.jmock.core.stub.ReturnStub; public abstract class AbstractDynamicMock implements DynamicMock { private InvocationDispatcher invocationDispatcher; private Class mockedType; private String name; private DynamicMockError failure = null; public AbstractDynamicMock( Class mockedType, String name ) { this(mockedType, name, new LIFOInvocationDispatcher()); } public AbstractDynamicMock( Class mockedType, String name, InvocationDispatcher invocationDispatcher ) { this.mockedType = mockedType; this.name = name; this.invocationDispatcher = invocationDispatcher; setupDefaultBehaviour(); } abstract public Object proxy(); public Class getMockedType() { return mockedType; } public void setDefaultStub( Stub newDefaultStub ) { invocationDispatcher.setDefaultStub(newDefaultStub); } public void addInvokable( Invokable invokable ) { invocationDispatcher.add(invokable); } public void reset() { //TODO write tests for this invocationDispatcher.clear(); forgetFailure(); setupDefaultBehaviour(); } public void verify() { forgetFailure(); try { invocationDispatcher.verify(); } catch (AssertionFailedError ex) { throw new AssertionFailedError( "mock object " + name + ": " + ex.getMessage()); } } public String toString() { return this.name; } public String getMockName() { return this.name; } public static String mockNameFromClass( Class c ) { return "mock" + Formatting.classShortName(c); } protected Object mockInvocation(Invocation invocation) throws Throwable { if (failure != null && !isObjectMethod(invocation.invokedMethod)) { throw failure; } try { Object result = invocationDispatcher.dispatch(invocation); invocation.checkReturnTypeCompatibility(result); return result; } catch (AssertionFailedError error) { failure = new DynamicMockError(this, invocation, invocationDispatcher, error.getMessage()); failure.fillInStackTrace(); throw failure; } } private boolean isObjectMethod(Method method) { return isToString(method) || isEquals(method) || isHashCode(method); } private boolean isEquals(Method method) { Class[] parameterTypes = method.getParameterTypes(); return method.getName().equals("equals") && parameterTypes.length == 1 && parameterTypes[0] == Object.class; } private boolean isToString(Method method) { return method.getName().equals("toString") && method.getParameterTypes().length == 0; } private boolean isHashCode(Method method) { return method.getName().equals("hashCode") && method.getParameterTypes().length == 0; } private void setupDefaultBehaviour() { addInvokable(hiddenInvocationMocker("toString", NoArgumentsMatcher.INSTANCE, new ReturnStub(name))); addInvokable(hiddenInvocationMocker("equals", new ArgumentsMatcher(new Constraint[]{new IsAnything()}), new IsSameAsProxyStub())); addInvokable(hiddenInvocationMocker("hashCode", NoArgumentsMatcher.INSTANCE, new HashCodeStub())); } private void forgetFailure() { failure = null; } private static final InvocationMocker.Describer NO_DESCRIPTION = new InvocationMocker.Describer() { public boolean hasDescription() { return false; } public void describeTo( StringBuffer buffer, List matchers, Stub stub, String name ) { } }; private InvocationMocker hiddenInvocationMocker( String methodName, InvocationMatcher arguments, Stub stub ) { InvocationMocker invocationMocker = new InvocationMocker(NO_DESCRIPTION); invocationMocker.addMatcher(new MethodNameMatcher(methodName)); invocationMocker.addMatcher(arguments); invocationMocker.setStub(stub); return invocationMocker; } private class IsSameAsProxyStub extends CustomStub { public IsSameAsProxyStub() { super("returns whether equal to proxy"); } public Object invoke( Invocation invocation ) throws Throwable { return new Boolean(invocation.parameterValues.get(0) == proxy()); } } private class HashCodeStub extends CustomStub { public HashCodeStub() { super("returns hashCode for proxy"); } public Object invoke( Invocation invocation ) throws Throwable { return new Integer(AbstractDynamicMock.this.hashCode()); } } } jmock-1.2.0.orig/jmock-core/org/jmock/core/Constraint.java0000644000175000017500000000074710605540374022176 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * A constraint over acceptable values. * @since 1.0 */ public interface Constraint extends SelfDescribing { /** * Evaluates the constraint for argument o. * * @param o the object against which the constraint is evaluated. * @return true if o meets the constraint, * false if it does not. */ boolean eval( Object o ); } jmock-1.2.0.orig/jmock-core/org/jmock/core/Formatting.java0000644000175000017500000000612710605540374022162 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.lang.reflect.Array; import java.util.Collection; /** * @since 1.0 */ public class Formatting { public static String toReadableString( Object element ) { if (element == null) { return "null"; } else if (element instanceof String) { return toJavaSyntax( (String)element ); } else if (element instanceof Character) { return "'" + toJavaSyntax(((Character)element).charValue()) + "'"; } else if (element instanceof Short) { return "<" + element.toString() + "s>"; } else if (element instanceof Long) { return "<" + element.toString() + "L>"; } else if (element instanceof Float) { return "<" + element.toString() + "F>"; } else if (element.getClass().isArray()) { return join(element, new StringBuffer()).toString(); } else { return "<" + element.toString() + ">"; } } private static String toJavaSyntax(String unformatted) { StringBuffer formatted = new StringBuffer(); formatted.append('"'); for (int i = 0; i < unformatted.length(); i++) { formatted.append(toJavaSyntax(unformatted.charAt(i))); } formatted.append('"'); return formatted.toString(); } private static String toJavaSyntax(char ch) { switch (ch) { case '"': return "\\\""; case '\n': return "\\n"; case '\r': return "\\r"; case '\t': return "\\t"; default: return new String(new char[]{ch}); } } public static StringBuffer join( Object array, StringBuffer buf ) { return join(array, buf, "[", "]"); } public static StringBuffer join( Collection collection, StringBuffer buf, String prefix, String postfix ) { return join(collection.toArray(), buf, prefix, postfix); } public static StringBuffer join( Collection collection, StringBuffer buf, String prefix, String separator, String postfix ) { return join(collection.toArray(), buf, prefix, separator, postfix); } public static StringBuffer join( Object array, StringBuffer buf, String prefix, String postfix ) { return join(array, buf, prefix, ", ", postfix); } public static StringBuffer join( Object array, StringBuffer buf, String prefix, String separator, String postfix ) { buf.append(prefix); for (int i = 0; i < Array.getLength(array); i++) { if (i > 0) buf.append(separator); buf.append(toReadableString(Array.get(array, i))); } buf.append(postfix); return buf; } public static String classShortName( Class c ) { String fullTypeName = c.getName(); return fullTypeName.substring(Math.max(fullTypeName.lastIndexOf('.'), fullTypeName.lastIndexOf('$')) + 1); } }jmock-1.2.0.orig/jmock-core/org/jmock/core/LIFOInvocationDispatcher.java0000644000175000017500000000133510605540374024636 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class LIFOInvocationDispatcher extends AbstractInvocationDispatcher { protected Iterator dispatchOrder( List invokablesList ) { final ListIterator i = invokablesList.listIterator(this.invokables.size()); return new Iterator() { public boolean hasNext() { return i.hasPrevious(); } public Object next() { return i.previous(); } public void remove() { throw new UnsupportedOperationException("immutable list"); } }; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/MockObjectSupportTestCase.java0000644000175000017500000002210110606776006025113 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.util.Collection; import org.jmock.core.constraint.And; import org.jmock.core.constraint.HasProperty; import org.jmock.core.constraint.HasPropertyWithValue; import org.jmock.core.constraint.HasToString; import org.jmock.core.constraint.IsAnything; import org.jmock.core.constraint.IsArrayContaining; import org.jmock.core.constraint.IsCloseTo; import org.jmock.core.constraint.IsCollectionContaining; import org.jmock.core.constraint.IsCompatibleType; import org.jmock.core.constraint.IsEqual; import org.jmock.core.constraint.IsIn; import org.jmock.core.constraint.IsInstanceOf; import org.jmock.core.constraint.IsMapContaining; import org.jmock.core.constraint.IsNot; import org.jmock.core.constraint.IsNull; import org.jmock.core.constraint.IsSame; import org.jmock.core.constraint.Or; import org.jmock.core.constraint.StringContains; import org.jmock.core.constraint.StringEndsWith; import org.jmock.core.constraint.StringStartsWith; import org.jmock.util.Dummy; /** * @since 1.0 */ public abstract class MockObjectSupportTestCase extends VerifyingTestCase { public static final Constraint ANYTHING = new IsAnything(); public static final Constraint NULL = new IsNull(); public static final Constraint NOT_NULL = new IsNot(NULL); public MockObjectSupportTestCase() { } public MockObjectSupportTestCase( String name ) { super(name); } public IsEqual eq( Object operand ) { return new IsEqual(operand); } public IsEqual eq( boolean operand ) { return eq(new Boolean(operand)); } public IsEqual eq( byte operand ) { return eq(new Byte(operand)); } public IsEqual eq( short operand ) { return eq(new Short(operand)); } public IsEqual eq( char operand ) { return eq(new Character(operand)); } public IsEqual eq( int operand ) { return eq(new Integer(operand)); } public IsEqual eq( long operand ) { return eq(new Long(operand)); } public IsEqual eq( float operand ) { return eq(new Float(operand)); } public IsEqual eq( double operand ) { return eq(new Double(operand)); } public IsCloseTo eq( double operand, double error ) { return new IsCloseTo(operand, error); } public IsSame same( Object operand ) { return new IsSame(operand); } public IsInstanceOf isA( Class operandClass ) { return new IsInstanceOf(operandClass); } public StringContains stringContains( String substring ) { return new StringContains(substring); } /** * @since 1.1.0 */ public StringContains contains( String substring ) { return stringContains(substring); } /** * @since 1.1.0 */ public StringStartsWith startsWith( String substring ) { return new StringStartsWith(substring); } /** * @since 1.1.0 */ public StringEndsWith endsWith( String substring ) { return new StringEndsWith(substring); } public IsNot not( Constraint c ) { return new IsNot(c); } public And and( Constraint left, Constraint right ) { return new And(left, right); } public Or or( Constraint left, Constraint right ) { return new Or(left, right); } /** * @deprecated Use MockObjectTestCase.newDummy instead */ public Object newDummy( Class dummyType ) { return Dummy.newDummy(dummyType); } /** * @deprecated Use MockObjectTestCase.newDummy instead */ public Object newDummy( Class dummyType, String name ) { return Dummy.newDummy(dummyType, name); } /** * @deprecated Use MockObjectTestCase.newDummy instead */ public Object newDummy(final String name) { return new Object() { public String toString() { return name; } }; } /** * @since 1.0.1 */ public void assertThat(Object actual, Constraint constraint) { if (!constraint.eval(actual)) { StringBuffer message = new StringBuffer("\nExpected: "); constraint.describeTo(message); message.append("\n got : ").append(actual).append('\n'); fail(message.toString()); } } public void assertThat(boolean actual, Constraint constraint) { assertThat(new Boolean(actual), constraint); } public void assertThat(byte actual, Constraint constraint) { assertThat(new Byte(actual), constraint); } public void assertThat(short actual, Constraint constraint) { assertThat(new Short(actual), constraint); } public void assertThat(char actual, Constraint constraint) { assertThat(new Character(actual), constraint); } public void assertThat(int actual, Constraint constraint) { assertThat(new Integer(actual), constraint); } public void assertThat(long actual, Constraint constraint) { assertThat(new Long(actual), constraint); } public void assertThat(float actual, Constraint constraint) { assertThat(new Float(actual), constraint); } public void assertThat(double actual, Constraint constraint) { assertThat(new Double(actual), constraint); } /** * @since 1.1.0 */ public HasPropertyWithValue hasProperty(String propertyName, Constraint expectation) { return new HasPropertyWithValue(propertyName, expectation); } /** * @since 1.1.0 */ public HasProperty hasProperty(String propertyName) { return new HasProperty(propertyName); } /** * @since 1.1.0 */ public HasToString toString(Constraint toStringConstraint) { return new HasToString(toStringConstraint); } /** * @since 1.1.0 */ public IsCompatibleType compatibleType(Class baseType) { return new IsCompatibleType(baseType); } /** * @since 1.1.0 */ public IsIn isIn(Collection collection) { return new IsIn(collection); } /** * @since 1.1.0 */ public IsIn isIn(Object[] array) { return new IsIn(array); } /** * @since 1.1.0 */ public IsCollectionContaining collectionContaining(Constraint elementConstraint) { return new IsCollectionContaining(elementConstraint); } /** * @since 1.1.0 */ public IsCollectionContaining collectionContaining(Object element) { return collectionContaining(eq(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(Constraint elementConstraint) { return new IsArrayContaining(elementConstraint); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(Object element) { return arrayContaining(eq(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(boolean element) { return arrayContaining(new Boolean(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(byte element) { return arrayContaining(new Byte(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(short element) { return arrayContaining(new Short(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(char element) { return arrayContaining(new Character(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(int element) { return arrayContaining(new Integer(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(long element) { return arrayContaining(new Long(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(float element) { return arrayContaining(new Float(element)); } /** * @since 1.1.0 */ public IsArrayContaining arrayContaining(double element) { return arrayContaining(new Double(element)); } /** * @since 1.1.0 */ public IsMapContaining mapContaining(Constraint keyConstraint, Constraint valueConstraint) { return new IsMapContaining(keyConstraint, valueConstraint); } /** * @since 1.1.0 */ public IsMapContaining mapContaining(Object key, Object value) { return mapContaining(eq(key), eq(value)); } /** * @since 1.1.0 */ public IsMapContaining mapWithKey(Object key) { return mapWithKey(eq(key)); } /** * @since 1.1.0 */ public IsMapContaining mapWithKey(Constraint keyConstraint) { return new IsMapContaining(keyConstraint, ANYTHING); } /** * @since 1.1.0 */ public IsMapContaining mapWithValue(Object value) { return mapWithValue(eq(value)); } /** * @since 1.1.0 */ public IsMapContaining mapWithValue(Constraint valueConstraint) { return new IsMapContaining(ANYTHING, valueConstraint); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/0000755000175000017500000000000010607017646021366 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/SubstringConstraint.java0000644000175000017500000000142610605540372026254 0ustar tonytonypackage org.jmock.core.constraint; import org.jmock.core.Constraint; import org.jmock.core.Formatting; public abstract class SubstringConstraint implements Constraint { protected final String substring; protected SubstringConstraint(final String substring) { this.substring = substring; } public boolean eval(Object o) { return o instanceof String && evalSubstringOf((String) o); } public StringBuffer describeTo(StringBuffer buffer) { return buffer.append("a string ") .append(relationship()) .append(" ") .append(Formatting.toReadableString(substring)); } protected abstract boolean evalSubstringOf(String string); protected abstract String relationship(); }jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsGreaterThan.java0000644000175000017500000000126610605540374024733 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; import org.jmock.core.Formatting; /** * Is the value greater than another {@link java.lang.Comparable} value? */ public class IsGreaterThan implements Constraint { private Comparable lowerLimit; public IsGreaterThan( Comparable lowerLimit ) { this.lowerLimit = lowerLimit; } public boolean eval( Object arg ) { return lowerLimit.compareTo(arg) < 0; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("a value greater than ") .append(Formatting.toReadableString(lowerLimit)); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsEqual.java0000644000175000017500000000322210605540372023566 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import java.lang.reflect.Array; import org.jmock.core.Constraint; import org.jmock.core.Formatting; /** * Is the value equal to another value, as tested by the * {@link java.lang.Object#equals} invokedMethod? */ public class IsEqual implements Constraint { private Object object; public IsEqual( Object equalArg ) { object = equalArg; } public boolean eval( Object arg ) { return areEqual(object, arg); } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("eq(") .append(Formatting.toReadableString(object)) .append(")"); } private static boolean areEqual( Object o1, Object o2 ) { if (o1 == null || o2 == null) { return o1 == null && o2 == null; } else if (isArray(o1)) { return isArray(o2) && areArraysEqual(o1, o2); } else { return o1.equals(o2); } } private static boolean areArraysEqual( Object o1, Object o2 ) { return areArrayLengthsEqual(o1, o2) && areArrayElementsEqual(o1, o2); } private static boolean areArrayLengthsEqual( Object o1, Object o2 ) { return Array.getLength(o1) == Array.getLength(o2); } private static boolean areArrayElementsEqual( Object o1, Object o2 ) { for (int i = 0; i < Array.getLength(o1); i++) { if (!areEqual(Array.get(o1, i), Array.get(o2, i))) return false; } return true; } private static boolean isArray( Object o ) { return o.getClass().isArray(); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsNot.java0000644000175000017500000000111410605540372023255 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * Calculates the logical negation of a constraint. */ public class IsNot implements Constraint { private Constraint constraint; public IsNot( Constraint constraint ) { this.constraint = constraint; } public boolean eval( Object arg ) { return !constraint.eval(arg); } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("not "); constraint.describeTo(buffer); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsSame.java0000644000175000017500000000144610605540374023414 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; import org.jmock.core.Formatting; /** * Is the value the same object as another value? */ public class IsSame implements Constraint { private Object object; /** * Creates a new instance of IsSame * * @param object The predicate evaluates to true only when the argument is * this object. */ public IsSame( Object object ) { this.object = object; } public boolean eval( Object arg ) { return arg == object; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("same(") .append(Formatting.toReadableString(object)) .append(")"); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/package.html0000644000175000017500000000036110605540372023642 0ustar tonytony

A collection of commonly useful constraints

@see org.jmock.core.Constraint @since 1.0 jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/And.java0000644000175000017500000000147410605540372022734 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * Calculates the logical conjunction of two constraints. Evaluation is * shortcut, so that the second constraint is not called if the first * constraint returns false. */ public class And implements Constraint { Constraint left, right; public And( Constraint left, Constraint right ) { this.left = left; this.right = right; } public boolean eval( Object o ) { return left.eval(o) && right.eval(o); } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("("); left.describeTo(buffer); buffer.append(" and "); right.describeTo(buffer); buffer.append(")"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsArrayContaining.java0000644000175000017500000000164410605540372025615 0ustar tonytonypackage org.jmock.core.constraint; import java.lang.reflect.Array; import org.jmock.core.Constraint; public class IsArrayContaining implements Constraint { private final Constraint elementConstraint; public IsArrayContaining(Constraint elementConstraint) { this.elementConstraint = elementConstraint; } public boolean eval(Object o) { return o != null && o.getClass().isArray() && arrayContainsMatchingElement(o); } private boolean arrayContainsMatchingElement(Object array) { int size = Array.getLength(array); for (int i = 0; i < size; i++) { if (elementConstraint.eval(Array.get(array, i))) return true; } return false; } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("an array containing "); elementConstraint.describeTo(buffer); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/StringEndsWith.java0000644000175000017500000000071210605540372025140 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; /** * Tests if the argument is a string that contains a substring. */ public class StringEndsWith extends SubstringConstraint { public StringEndsWith(String substring) { super(substring); } protected boolean evalSubstringOf(String s) { return s.endsWith(substring); } protected String relationship() { return "ending with"; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/HasProperty.java0000644000175000017500000000205010605540372024501 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import java.beans.IntrospectionException; import org.jmock.core.Constraint; import org.jmock.util.PropertyUtil; /** * Constraint that checks that an object has a JavaBean property * with the specified name. If an error occurs while introspecting * the object then this is treated as a constraint failure. * * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman * @since 1.1.0 */ public class HasProperty implements Constraint { private String propertyName; public HasProperty(String propertyName) { this.propertyName = propertyName; } public boolean eval(Object obj) { try { return PropertyUtil.getPropertyDescriptor(propertyName, obj) != null; } catch (IntrospectionException e) { // introspection failure is treated as a constraint failure return false; } } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("hasProperty(\""); buffer.append(propertyName); buffer.append("\")"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsInstanceOf.java0000644000175000017500000000142610605540372024554 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * Tests whether the value is an instance of a class. */ public class IsInstanceOf implements Constraint { private Class theClass; /** * Creates a new instance of IsInstanceOf * * @param theClass The predicate evaluates to true for instances of this class * or one of its subclasses. */ public IsInstanceOf( Class theClass ) { this.theClass = theClass; } public boolean eval( Object arg ) { return theClass.isInstance(arg); } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("an instance of ") .append(theClass.getName()); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/StringContains.java0000644000175000017500000000071410605540372025173 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; /** * Tests if the argument is a string that contains a substring. */ public class StringContains extends SubstringConstraint { public StringContains(String substring) { super(substring); } protected boolean evalSubstringOf(String s) { return s.indexOf(substring) >= 0; } protected String relationship() { return "containing"; } }jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/HasToString.java0000644000175000017500000000112410605540372024427 0ustar tonytonypackage org.jmock.core.constraint; import org.jmock.core.Constraint; public class HasToString implements Constraint { private final Constraint toStringConstraint; public HasToString(Constraint toStringConstraint) { this.toStringConstraint = toStringConstraint; } public boolean eval(Object o) { return toStringConstraint.eval(o.toString()); } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("toString("); toStringConstraint.describeTo(buffer); buffer.append(")"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsMapContaining.java0000644000175000017500000000226310605540374025254 0ustar tonytonypackage org.jmock.core.constraint; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import org.jmock.core.Constraint; public class IsMapContaining implements Constraint { private final Constraint keyConstraint; private final Constraint valueConstraint; public IsMapContaining(Constraint keyConstraint, Constraint valueConstraint) { this.keyConstraint = keyConstraint; this.valueConstraint = valueConstraint; } public boolean eval(Object o) { if (o != null && o instanceof Map) { Map map = (Map)o; for (Iterator i = map.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Entry) i.next(); if (keyConstraint.eval(entry.getKey()) && valueConstraint.eval(entry.getValue())) { return true; } } } return false; } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("map containing ["); keyConstraint.describeTo(buffer); buffer.append("->"); valueConstraint.describeTo(buffer); buffer.append("]"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsIn.java0000644000175000017500000000125410605540374023072 0ustar tonytonypackage org.jmock.core.constraint; import java.util.Arrays; import java.util.Collection; import org.jmock.core.Constraint; import org.jmock.core.Formatting; public class IsIn implements Constraint { private final Collection collection; public IsIn(Collection collection) { this.collection = collection; } public IsIn(Object[] elements) { collection = Arrays.asList(elements); } public boolean eval(Object o) { return collection.contains(o); } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("one of "); Formatting.join(collection, buffer, "{", "}"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/HasPropertyWithValue.java0000644000175000017500000000737310605540372026347 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.jmock.core.Constraint; import org.jmock.util.PropertyUtil; /** * Constraint that asserts that a JavaBean property on an argument passed to the * mock object meets the provided constraint. This is useful for when objects * are created within code under test and passed to a mock object, and you wish * to assert that the created object has certain properties. * *

Example Usage

* Consider the situation where we have a class representing a person, which * follows the basic JavaBean convention of having get() and possibly set() * methods for it's properties: * public class Person { * private String name; * * public Person(String person) { * this.person = person; * } * * public String getName() { * return name; * } * } * And that these person * objects are generated within a piece of code under test (a class named * PersonGenerator). This object is sent to one of our mock objects which * overrides the PersonGenerationListener interface: * public interface PersonGenerationListener { * public void personGenerated(Person person); * } * * In order to check that the code under test generates a person with name * "Iain" we would do the following: * * * Mock personGenListenerMock = mock(PersonGenerationListener.class); * personGenListenerMock.expects(once()).method("personGenerated").with(and(isA(Person.class), hasProperty("Name", eq("Iain"))); * PersonGenerationListener listener = (PersonGenerationListener)personGenListenerMock.proxy(); * * * If an exception is thrown by the getter method for a property, the property * does not exist, is not readable, or a reflection related exception is thrown * when trying to invoke it then this is treated as an evaluation failure and * the eval method will return false. * * This constraint class will also work with JavaBean objects that have explicit * bean descriptions via an associated BeanInfo description class. See the * JavaBeans specification for more information: * * http://java.sun.com/products/javabeans/docs/index.html * * @author Iain McGinniss * @author Nat Pryce * @author Steve Freeman * @since 1.1.0 */ public class HasPropertyWithValue implements Constraint { private static final Object[] NO_ARGUMENTS = new Object[0]; private String propertyName; private Constraint expectation; public HasPropertyWithValue(String propertyName, Constraint expectation) { this.propertyName = propertyName; this.expectation = expectation; } public boolean eval(Object argument) { try { Method readMethod = getReadMethod(argument); return readMethod != null && expectation.eval(readMethod.invoke(argument, NO_ARGUMENTS)); } catch (IntrospectionException e) { } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } return false; } private Method getReadMethod(Object argument) throws IntrospectionException { PropertyDescriptor property = PropertyUtil.getPropertyDescriptor(propertyName, argument); return property == null ? null : property.getReadMethod(); } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("hasProperty(\""); buffer.append(propertyName); buffer.append("\", "); expectation.describeTo(buffer); buffer.append(")"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsLessThan.java0000644000175000017500000000125210605540374024243 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; import org.jmock.core.Formatting; /** * Is the value less than another {@link java.lang.Comparable} value? */ public class IsLessThan implements Constraint { private Comparable upperLimit; public IsLessThan( Comparable upperLimit ) { this.upperLimit = upperLimit; } public boolean eval( Object arg ) { return upperLimit.compareTo(arg) > 0; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("a value less than ") .append(Formatting.toReadableString(upperLimit)); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsCollectionContaining.java0000644000175000017500000000172510605540372026632 0ustar tonytonypackage org.jmock.core.constraint; import java.util.Collection; import java.util.Iterator; import org.jmock.core.Constraint; public class IsCollectionContaining implements Constraint { private final Constraint elementConstraint; public IsCollectionContaining(Constraint elementConstraint) { this.elementConstraint = elementConstraint; } public boolean eval(Object o) { return o != null && o instanceof Collection && collectionContainsMatchingElement((Collection)o); } private boolean collectionContainsMatchingElement(Collection collection) { Iterator i = collection.iterator(); while (i.hasNext()) { if (elementConstraint.eval(i.next())) return true; } return false; } public StringBuffer describeTo(StringBuffer buffer) { buffer.append("a collection containing "); elementConstraint.describeTo(buffer); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/StringStartsWith.java0000644000175000017500000000072110605540372025527 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; /** * Tests if the argument is a string that contains a substring. */ public class StringStartsWith extends SubstringConstraint { public StringStartsWith(String substring) { super(substring); } protected boolean evalSubstringOf(String s) { return s.startsWith(substring); } protected String relationship() { return "starting with"; } }jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsAnything.java0000644000175000017500000000121710605540372024302 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * A constraint that always returns true. */ public class IsAnything implements Constraint { public static final IsAnything INSTANCE = new IsAnything(); private String description; public IsAnything() { this("ANYTHING"); } public IsAnything( String description ) { this.description = description; } public boolean eval( Object o ) { return true; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append(description); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsCloseTo.java0000644000175000017500000000143510605540372024073 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * Is the value a number equal to a value within some range of * acceptable error? */ public class IsCloseTo implements Constraint { private double error; private double value; public IsCloseTo( double value, double error ) { this.error = error; this.value = value; } public boolean eval( Object arg ) { double argValue = ((Number)arg).doubleValue(); return Math.abs((argValue - value)) <= error; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("a numeric value within ") .append(error) .append(" of ") .append(value); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsNull.java0000644000175000017500000000055610605540372023440 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * Is the value null? */ public class IsNull implements Constraint { public boolean eval( Object o ) { return o == null; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("null"); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsEventFrom.java0000644000175000017500000000255210605540374024433 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import java.util.EventObject; import org.jmock.core.Constraint; /** * Tests if the value is an event announced by a specific object. */ public class IsEventFrom implements Constraint { private Class eventClass; private Object source; /** * Constructs an IsEventFrom predicate that returns true for any object * derived from {@link java.util.EventObject}announced by source * . */ public IsEventFrom( Object source ) { this(EventObject.class, source); } /** * Constructs an IsEventFrom predicate that returns true for any object * derived from event_class announced by source. */ public IsEventFrom( Class eventClass, Object source ) { this.eventClass = eventClass; this.source = source; } public boolean eval( Object o ) { return (o instanceof EventObject) && eventClass.isInstance(o) && eventHasSameSource((EventObject)o); } private boolean eventHasSameSource(EventObject ev) { return ev.getSource() == source; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append("an event of type ") .append(eventClass.getName()) .append(" from ") .append(source); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsNothing.java0000644000175000017500000000103510605540374024127 0ustar tonytonypackage org.jmock.core.constraint; import org.jmock.core.Constraint; public class IsNothing implements Constraint { public static final IsNothing INSTANCE = new IsNothing(); private String description; public IsNothing() { this("NOTHING"); } public IsNothing( String description ) { this.description = description; } public boolean eval( Object o ) { return false; } public StringBuffer describeTo( StringBuffer buffer ) { return buffer.append(description); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/Or.java0000644000175000017500000000147010605540372022606 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core.constraint; import org.jmock.core.Constraint; /** * Calculates the logical disjunction of two constraints. Evaluation is * shortcut, so that the second constraint is not called if the first * constraint returns true. */ public class Or implements Constraint { Constraint left, right; public Or( Constraint left, Constraint right ) { this.left = left; this.right = right; } public boolean eval( Object o ) { return left.eval(o) || right.eval(o); } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append("("); left.describeTo(buffer); buffer.append(" or "); right.describeTo(buffer); buffer.append(")"); return buffer; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/IsCompatibleType.java0000644000175000017500000000073410605540372025445 0ustar tonytonypackage org.jmock.core.constraint; import org.jmock.core.Constraint; public class IsCompatibleType implements Constraint { private final Class type; public IsCompatibleType(Class type) { this.type = type; } public boolean eval(Object o) { return o instanceof Class && type.isAssignableFrom((Class)o); } public StringBuffer describeTo(StringBuffer buffer) { return buffer.append("type < " + type.getName()); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/StubMatchersCollection.java0000644000175000017500000000037110605540374024463 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * @since 1.0 */ public interface StubMatchersCollection { void setName( String name ); void addMatcher( InvocationMatcher matcher ); void setStub( Stub stub ); } jmock-1.2.0.orig/jmock-core/org/jmock/core/InvocationMatcher.java0000644000175000017500000000044510605540374023462 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * @since 1.0 */ public interface InvocationMatcher extends Verifiable, SelfDescribing { boolean matches( Invocation invocation ); void invoked( Invocation invocation ); boolean hasDescription(); } jmock-1.2.0.orig/jmock-core/org/jmock/core/CoreMock.java0000644000175000017500000000211210605540374021540 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; /** * @since 1.0 */ public class CoreMock extends AbstractDynamicMock implements InvocationHandler { private Object proxy; public CoreMock( Class mockedType, String name ) { this(mockedType, name, new LIFOInvocationDispatcher()); } public CoreMock( Class mockedType, String name, InvocationDispatcher invocationDispatcher ) { super(mockedType, name, invocationDispatcher); this.proxy = Proxy.newProxyInstance(mockedType.getClassLoader(), new Class[]{mockedType}, this); } public Object proxy() { return this.proxy; } public Object invoke( Object invokedProxy, Method method, Object[] args ) throws Throwable { return mockInvocation(new Invocation(invokedProxy, method, args)); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/FIFOInvocationDispatcher.java0000644000175000017500000000047010605540374024627 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.util.Iterator; import java.util.List; public class FIFOInvocationDispatcher extends AbstractInvocationDispatcher { protected Iterator dispatchOrder( List invokablesList ) { return invokablesList.iterator(); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/Invocation.java0000644000175000017500000000753110605540374022161 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.lang.reflect.Method; import java.util.*; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import junit.framework.Assert; /** * The static details about a method and the run-time details of its invocation. * @since 1.0 */ public class Invocation implements SelfDescribing { public final Object invokedObject; public final Method invokedMethod; public final List parameterValues; // Yuck, but there doesn't seem to be a better way. private static final Map BOX_TYPES = makeBoxTypesMap(); public Invocation( Object invoked, Method method, Object[] parameterValues ) { this.invokedObject = invoked; this.invokedMethod = method; this.parameterValues = parameterValues == null ? Collections.EMPTY_LIST : Collections.unmodifiableList(Arrays.asList(parameterValues)); } public String toString() { return describeTo(new StringBuffer()).toString(); } public boolean equals( Object other ) { return (other instanceof Invocation) && this.equals((Invocation)other); } public boolean equals( Invocation other ) { return other != null && invokedObject == other.invokedObject && invokedMethod.equals(other.invokedMethod) && parameterValues.equals(other.parameterValues); } public int hashCode() { return invokedObject.hashCode() ^ invokedMethod.hashCode() ^ parameterValues.hashCode(); } public StringBuffer describeTo( StringBuffer buffer ) { buffer.append(invokedObject.toString()).append(".").append(invokedMethod.getName()); Formatting.join(parameterValues, buffer, "(", ")"); return buffer; } public void checkReturnTypeCompatibility(final Object result) { Class returnType = invokedMethod.getReturnType(); if (returnType == void.class) { failIfReturnTypeIsNotNull(result); } else if (result == null) { failIfReturnTypeIsPrimitive(); } else { Class valueType = result.getClass(); if (!isCompatible(returnType, valueType)) { reportTypeError(returnType, valueType); } } } private boolean isCompatible( Class returnType, Class valueType ) { if (returnType.isPrimitive()) { return isBoxedType(returnType, valueType); } return returnType.isAssignableFrom(valueType); } private boolean isBoxedType( Class primitiveType, Class referenceType ) { return BOX_TYPES.get(primitiveType) == referenceType; } private void failIfReturnTypeIsNotNull(final Object result) { Assert.assertNull("tried to return a value from a void method", result); } private void failIfReturnTypeIsPrimitive() { Class returnType = invokedMethod.getReturnType(); Assert.assertFalse( "tried to return null value from method returning " + returnType.getName(), returnType.isPrimitive()); } private void reportTypeError( Class returnType, Class valueType ) { Assert.fail("tried to return an incompatible value: " + "expected a " + returnType.getName() + " but returned a " + valueType.getName()); } private static Map makeBoxTypesMap() { HashMap map = new HashMap(); map.put(boolean.class, Boolean.class); map.put(byte.class, Byte.class); map.put(char.class, Character.class); map.put(short.class, Short.class); map.put(int.class, Integer.class); map.put(long.class, Long.class); map.put(float.class, Float.class); map.put(double.class, Double.class); return map; } } jmock-1.2.0.orig/jmock-core/org/jmock/core/VerifyingTestCase.java0000644000175000017500000000313110605540374023436 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import junit.framework.TestCase; import org.jmock.util.Verifier; /** * A {@link junit.framework.TestCase} that verifies {@link org.jmock.core.Verifiable} * fields and registered Verifiable objects after the test has run and before the fixture * has been torn down. * * @since 1.0 */ public abstract class VerifyingTestCase extends TestCase { private List objectsThatRequireVerification = new ArrayList(); public VerifyingTestCase() { super(); } public VerifyingTestCase( String name ) { super(name); } /* This is virtually a copy/paste of the same invokedMethod in the TestCase class to allow * overriding of runTest in the normal manner. * * @see junit.framework.TestCase#runBare() */ public void runBare() throws Throwable { setUp(); try { runTest(); verify(); } finally { tearDown(); } } public void registerToVerify( Verifiable verifiable ) { objectsThatRequireVerification.add(verifiable); } public void unregisterToVerify( Verifiable verifiable ) { objectsThatRequireVerification.remove(verifiable); } public void verify() { for (Iterator iterator = objectsThatRequireVerification.iterator(); iterator.hasNext();) { Verifiable verifiable = (Verifiable)iterator.next(); verifiable.verify(); } Verifier.verifyObject(this); } } jmock-1.2.0.orig/jmock-core/org/jmock/core/DynamicMock.java0000644000175000017500000000047410605540374022245 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * * @since 1.0 * */ public interface DynamicMock extends Verifiable { Class getMockedType(); Object proxy(); void setDefaultStub( Stub newDefaultStub ); void addInvokable( Invokable invokable ); void reset(); } jmock-1.2.0.orig/jmock-core/org/jmock/core/SelfDescribing.java0000644000175000017500000000074510605540374022733 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * An object that can describe itself. * Used when reporting a missed expectation in a test case. * @since 1.0 */ public interface SelfDescribing { /** * Appends the description of this object to the buffer. * * @param buffer The buffer that the description is appended to. * @return The buffer passed to the invokedMethod. */ StringBuffer describeTo( StringBuffer buffer ); } jmock-1.2.0.orig/jmock-core/org/jmock/core/Verifiable.java0000644000175000017500000000115710605540374022116 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.core; /** * A Verifiable is an object that can confirm at the end of a unit test that * the correct behvaiour has occurred. * * @see org.jmock.util.Verifier Verifier to check all the Verifiables in an object. * @since 1.0 */ public interface Verifiable { /** * Throw an AssertionFailedException if any expectations have not been met. * Implementations of this method must be idempotent: jMock can call this method * more than once when verifying expectations at the end of a test. */ public abstract void verify(); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/0000755000175000017500000000000010607017646017700 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/builder/BuilderNamespace.java0000644000175000017500000000046010605540376023745 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; /** * @since 1.0 */ public interface BuilderNamespace { MatchBuilder lookupID( String id ); void registerMethodName( String id, MatchBuilder invocation ); void registerUniqueID( String id, MatchBuilder invocation ); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/ArgumentsMatchBuilder.java0000644000175000017500000000112710605540376024774 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; import org.jmock.core.Constraint; /** * @since 1.0 */ public interface ArgumentsMatchBuilder extends MatchBuilder { MatchBuilder with( Constraint[] argumentConstraints ); MatchBuilder with( Constraint arg1 ); MatchBuilder with( Constraint arg1, Constraint arg2 ); MatchBuilder with( Constraint arg1, Constraint arg2, Constraint arg3 ); MatchBuilder with( Constraint arg1, Constraint arg2, Constraint arg3, Constraint arg4 ); MatchBuilder withNoArguments(); MatchBuilder withAnyArguments(); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/IdentityBuilder.java0000644000175000017500000000023310605540376023640 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; /** * @since 1.0 */ public interface IdentityBuilder { void id( String id ); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/NameMatchBuilder.java0000644000175000017500000000046410605540376023712 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; import org.jmock.core.Constraint; /** * @since 1.0 */ public interface NameMatchBuilder extends ArgumentsMatchBuilder { ArgumentsMatchBuilder method( String name ); ArgumentsMatchBuilder method( Constraint nameConstraint ); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/InvocationMockerDescriber.java0000644000175000017500000000363410605540376025645 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; import java.util.Iterator; import java.util.List; import org.jmock.core.InvocationMatcher; import org.jmock.core.InvocationMocker.Describer; import org.jmock.core.Stub; import org.jmock.core.matcher.MethodNameMatcher; import org.jmock.core.matcher.ArgumentsMatcher; /* This encapsulates knowledge about how the InvocationMockerBuilder class * adds matchers to an InvocationMocker. Therefore it should be considered * to be part of the implementation of the InvocationMockerBuilder class. */ /** * @since 1.0 */ public class InvocationMockerDescriber implements Describer { private static final String SEP = ", "; public boolean hasDescription() { return true; } public void describeTo( StringBuffer buffer, List matchers, Stub stub, String name ) { Iterator i = matchers.iterator(); boolean needSeparator = false; boolean lastWasMethodName = false; while (i.hasNext()) { InvocationMatcher matcher = (InvocationMatcher)i.next(); if (!matcher.hasDescription()) continue; if (matcher instanceof MethodNameMatcher) { if (!needSeparator) buffer.append("stub"); // first matcher buffer.append(": "); lastWasMethodName = true; } else if( matcher instanceof ArgumentsMatcher ) { if (needSeparator && !lastWasMethodName) buffer.append(SEP); lastWasMethodName = false; } else { if (needSeparator) buffer.append(SEP); lastWasMethodName = false; } matcher.describeTo(buffer); needSeparator = true; } if (needSeparator) buffer.append(SEP); stub.describeTo(buffer); if (name != null) buffer.append(" [").append(name).append("]"); } } jmock-1.2.0.orig/jmock-core/org/jmock/builder/MatchBuilder.java0000644000175000017500000000056710605540376023115 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; import org.jmock.core.InvocationMatcher; /** * @since 1.0 */ public interface MatchBuilder extends StubBuilder { MatchBuilder match( InvocationMatcher customMatcher ); MatchBuilder after( String previousCallID ); MatchBuilder after( BuilderNamespace otherMock, String previousCallID ); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/StubBuilder.java0000644000175000017500000000037610605540376022774 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; import org.jmock.core.Stub; /** * @since 1.0 */ public interface StubBuilder extends IdentityBuilder { IdentityBuilder will( Stub stubAction ); IdentityBuilder isVoid(); } jmock-1.2.0.orig/jmock-core/org/jmock/builder/InvocationMockerBuilder.java0000644000175000017500000001254410606777154025340 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.builder; import java.lang.reflect.Method; import junit.framework.AssertionFailedError; import org.jmock.core.Constraint; import org.jmock.core.InvocationMatcher; import org.jmock.core.Stub; import org.jmock.core.StubMatchersCollection; import org.jmock.core.constraint.IsNull; import org.jmock.core.matcher.*; import org.jmock.core.stub.VoidStub; /** * @since 1.0 */ public class InvocationMockerBuilder implements NameMatchBuilder { private StubMatchersCollection mocker; private BuilderNamespace builderNamespace; private Class mockedType; public InvocationMockerBuilder( StubMatchersCollection mocker, BuilderNamespace idTable, Class mockedType ) { this.mocker = mocker; this.builderNamespace = idTable; this.mockedType = mockedType; } public ArgumentsMatchBuilder method( Constraint nameConstraint ) { return addMatcher(new MethodNameMatcher(nameConstraint)); } public ArgumentsMatchBuilder method( String name ) { checkLegalMethodName(name); checkExistingMethodName(name); addMatcher(new MethodNameMatcher(name)); builderNamespace.registerMethodName(name, this); return this; } private void checkLegalMethodName( String name ) { if( !isLegalMethodName(name) ) { throw new IllegalArgumentException("illegal method name: " + name + " is not a legal Java identifier"); } } private boolean isLegalMethodName( String name ) { if( !Character.isJavaIdentifierStart(name.charAt(0)) ) return false; for( int i = 1; i < name.length(); i++ ) { if( !Character.isJavaIdentifierPart(name.charAt(i))) return false; } return true; } private void checkExistingMethodName( String name ) { if( !typeDefinesMethodNamed(mockedType,name) && !typeDefinesMethodNamed(Object.class,name) ) { throw new AssertionFailedError("no method named " + name + " is defined in type "+mockedType); } } private boolean typeDefinesMethodNamed( Class type, String name ) { Method[] methods = type.getMethods(); for( int i = 0; i < methods.length; i++ ) { if( methods[i].getName().equals(name) ) return true; } return false; } public MatchBuilder match( InvocationMatcher customMatcher ) { return addMatcher(customMatcher); } public MatchBuilder with( Constraint arg1 ) { return with(new Constraint[]{arg1}); } public MatchBuilder with( Constraint arg1, Constraint arg2 ) { return with(new Constraint[]{arg1, arg2}); } public MatchBuilder with( Constraint arg1, Constraint arg2, Constraint arg3 ) { return with(new Constraint[]{arg1, arg2, arg3}); } public MatchBuilder with( Constraint arg1, Constraint arg2, Constraint arg3, Constraint arg4 ) { return with(new Constraint[]{arg1, arg2, arg3, arg4}); } public MatchBuilder with( Constraint[] constraints ) { for (int i = 0; i < constraints.length; i++) { if (constraints[i] == null) { constraints[i] = new IsNull(); } } return addMatcher(new ArgumentsMatcher(constraints)); } public MatchBuilder withNoArguments() { return addMatcher(NoArgumentsMatcher.INSTANCE); } public MatchBuilder withAnyArguments() { return addMatcher(AnyArgumentsMatcher.INSTANCE); } public IdentityBuilder will( Stub stubAction ) { setStub(stubAction); return this; } public IdentityBuilder isVoid() { setStub(VoidStub.INSTANCE); return this; } private void setStub( Stub stubAction ) { mocker.setStub(stubAction); } public IdentityBuilder expect( InvocationMatcher expectation ) { return addMatcher(expectation); } public void id( String invocationID ) { mocker.setName(invocationID); builderNamespace.registerUniqueID(invocationID, this); } public MatchBuilder after( String priorCallID ) { setupOrderingMatchers(builderNamespace, priorCallID, priorCallID); return this; } public MatchBuilder after( BuilderNamespace otherMock, String priorCallID ) { setupOrderingMatchers(otherMock, priorCallID, priorCallID + " on " + otherMock); return this; } private void setupOrderingMatchers( BuilderNamespace idTable, String priorCallID, String priorCallDescription ) { MatchBuilder priorCallBuilder = idTable.lookupID(priorCallID); if (priorCallBuilder == this) { throw new AssertionFailedError("confusing identifier of prior invocation \"" + priorCallID + "\"; " + "give it an explicit call identifier"); } InvokedRecorder priorCallRecorder = new InvokedRecorder(); priorCallBuilder.match(priorCallRecorder); mocker.addMatcher(new InvokedAfterMatcher(priorCallRecorder, priorCallDescription)); } private InvocationMockerBuilder addMatcher( InvocationMatcher matcher ) { mocker.addMatcher(matcher); return this; } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/0000755000175000017500000000000010607017646020575 5ustar tonytonyjmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationSet.java0000644000175000017500000000177410605540372024403 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Collection; import java.util.HashSet; public class ExpectationSet extends AbstractExpectationCollection { private HashSet myExpectedItems = new HashSet(); private HashSet myActualItems = new HashSet(); public ExpectationSet( String name ) { super(name); } protected void checkImmediateValues( Object actualItem ) { AssertMo.assertTrue(myName + " received an unexpected item\nUnexpected:" + actualItem, new HashSet(myExpectedItems).contains(actualItem)); } protected Collection getActualCollection() { return myActualItems; } protected Collection getExpectedCollection() { return myExpectedItems; } public void verify() { assertEquals("did not receive the expected collection items.", new HashSet(getExpectedCollection()), new HashSet(getActualCollection())); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationCollection.java0000644000175000017500000000206010605540372025730 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Enumeration; import java.util.Iterator; /** * An ExpectationCollection is an expectation that supports multiple values, such as lists * and sets. *

* The addition methods distinguish between adding a single value and unpacking the contents of * a collection. We have to make this distinction so that it is possible to add an array, enumeration, * or iterator as a single expected object, rather than adding its contents. * @since 1.0 */ public interface ExpectationCollection extends Expectation { void addActual( Object actual ); void addActual( long actual ); void addActualMany( Object[] actuals ); void addActualMany( Enumeration actuals ); void addActualMany( Iterator actuals ); void addExpected( Object expected ); void addExpected( long expected ); void addExpectedMany( Object[] expectedItems ); void addExpectedMany( Enumeration expectedItems ); void addExpectedMany( Iterator expectedItems ); } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ReturnValues.java0000644000175000017500000000336010605540372024074 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Collection; import java.util.Vector; import junit.framework.AssertionFailedError; /** * Sequence values as required by MockMaker * This is a generic class that should have been introduced to the mockobjects code stream instead of * being separately included in org.mockobjects. * It is possibly similar to a ReturnObjectList? */ public class ReturnValues { private String myName; protected Vector myContents = new Vector(); private boolean myKeepUsingLastReturnValue = false; public ReturnValues() { this("Generate me with a useful name!", true); } public ReturnValues( String name, boolean keepUsingLastReturnValue ) { myName = name; myKeepUsingLastReturnValue = keepUsingLastReturnValue; } public ReturnValues( boolean keepUsingLastReturnValue ) { this("Generate me with a useful name!", keepUsingLastReturnValue); } public void add( Object element ) { myContents.addElement(element); } public void addAll( Collection returnValues ) { myContents.addAll(returnValues); } public Object getNext() { if (myContents.isEmpty()) { throw new AssertionFailedError(getClass().getName() + "[" + myName + "] was not setup with enough values"); } return pop(); } public boolean isEmpty() { return myContents.size() == 0; } protected Object pop() { Object result = myContents.firstElement(); boolean shouldNotRemoveElement = myContents.size() == 1 && myKeepUsingLastReturnValue; if (!shouldNotRemoveElement) { myContents.removeElementAt(0); } return result; } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/AbstractExpectationCollection.java0000644000175000017500000000542710605540372027426 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; abstract public class AbstractExpectationCollection extends AbstractExpectation implements ExpectationCollection { public AbstractExpectationCollection( String name ) { super(name); } public void addActual( Object actualItem ) { getActualCollection().add(actualItem); if (shouldCheckImmediately()) { checkImmediateValues(actualItem); } } public void addActual( int actualItem ) { addActual(new Integer(actualItem)); } public void addActualMany( Object[] items ) { if (items == null) return; for (int i = 0; i < items.length; ++i) { addActual(items[i]); } } public void addActualMany( Enumeration items ) { while (items.hasMoreElements()) { addActual(items.nextElement()); } } public void addActualMany( Iterator items ) { while (items.hasNext()) { addActual(items.next()); } } public void addExpected( int expectedItem ) { addExpected(new Integer(expectedItem)); } public void addExpected( Object expectedItem ) { getExpectedCollection().add(expectedItem); setHasExpectations(); } public void addExpectedMany( Object[] expectedItems ) { for (int i = 0; i < expectedItems.length; ++i) { addExpected(expectedItems[i]); } setHasExpectations(); } public void addExpectedMany( Enumeration expectedItems ) { while (expectedItems.hasMoreElements()) { addExpected(expectedItems.nextElement()); } setHasExpectations(); } public void addExpectedMany( Iterator expectedItems ) { while (expectedItems.hasNext()) { addExpected(expectedItems.next()); } setHasExpectations(); } abstract protected void checkImmediateValues( Object actualItem ); public void clearActual() { getActualCollection().clear(); } protected void clearExpectation() { getExpectedCollection().clear(); } abstract protected Collection getActualCollection(); abstract protected Collection getExpectedCollection(); public void setExpectNothing() { clearExpectation(); setHasExpectations(); } public void verify() { assertEquals("did not receive the expected collection items.", getExpectedCollection(), getActualCollection()); } public void addActual( long actual ) { addActual(new Long(actual)); } public void addExpected( long expected ) { addExpected(new Long(expected)); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationMap.java0000644000175000017500000000202510605540372024353 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.HashMap; import org.jmock.core.Verifiable; public class ExpectationMap implements Expectation, Verifiable { private HashMap myEntries; private ExpectationSet myKeys; public ExpectationMap( String name ) { myEntries = new HashMap(); myKeys = new ExpectationSet(name + " keys"); } public void addExpected( Object key, Object value ) { myKeys.addExpected(key); myEntries.put(key, value); } public void addExpectedMissing( Object key ) { myKeys.addExpected(key); } public Object get( Object key ) { myKeys.addActual(key); return myEntries.get(key); } public boolean hasExpectations() { return myKeys.hasExpectations(); } public void setExpectNothing() { myKeys.setExpectNothing(); } public void setFailOnVerify() { myKeys.setFailOnVerify(); } public void verify() { myKeys.verify(); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ReturnObjectBag.java0000644000175000017500000001211310605540372024451 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Hashtable; import java.util.Iterator; import org.jmock.core.Verifiable; /** * The ReturnObjectBag is a map containing instances of ReturnObjectList. * A single instance is held for each mapkey. Every time a call to putObjectToReturn or * getNextReturnObject is made an object is added or removed from the ReturnObjectList for * the given key. * This allows the ReturnObjectBag to be used to return an ordered list of objects for each key * regardless of the order in which the key requests are made. * * @author Jeff Martin * @version $Revision: 1.1 $ * @see ReturnObjectList */ public class ReturnObjectBag implements Verifiable { private final Hashtable returnObjectLists = new Hashtable(); private final String name; /** * @param name Name used to describe an instance of ReturnObjectBag in error messages */ public ReturnObjectBag( String name ) { this.name = name; } /** * Places an object into the list of return objects for a particular key * * @param key the key against which the object will be stored * @param value the value to be added to the list for that key * @see ReturnObjectList#addObjectToReturn */ public void putObjectToReturn( Object key, Object value ) { if (key == null) { key = Null.NULL; } ReturnObjectList returnObjectList = (ReturnObjectList)returnObjectLists.get(key); if (returnObjectList == null) { returnObjectList = new ReturnObjectList(name + "." + key.toString()); returnObjectLists.put(key, returnObjectList); } returnObjectList.addObjectToReturn(value); } /** * Places an object into the list of return objects for a particular int key * * @param key the key against which the object will be stored * @param value the value to be added to the list for that key * @see ReturnObjectList#addObjectToReturn */ public void putObjectToReturn( int key, Object value ) { putObjectToReturn(new Integer(key), value); } /** * Places an int into the list of return objects for a particular key. The value can be retrieved * using the getNextReturnInt invokedMethod * * @param key the key against which the object will be stored * @param value the value to be added to the list for that key * @see ReturnObjectList#addObjectToReturn * @see #getNextReturnInt */ public void putObjectToReturn( Object key, int value ) { putObjectToReturn(key, new Integer(value)); } /** * Places an boolean into the list of return objects for a particular key. The value can be retrieved * using the getNextReturnBoolean invokedMethod * * @param key the key against which the object will be stored * @param value the value to be added to the list for that key * @see ReturnObjectList#addObjectToReturn * @see #getNextReturnBoolean */ public void putObjectToReturn( Object key, boolean value ) { putObjectToReturn(key, new Boolean(value)); } /** * Checks each the list for each key to verify that all no objects remain * in the list for that key. * * @see ReturnObjectList#verify */ public void verify() { for (Iterator it = returnObjectLists.values().iterator(); it.hasNext();) { ((ReturnObjectList)it.next()).verify(); } } /** * Returns the next object in the ReturnObjectList for a given key. * The call will throw an AssertFailError if the requested key is * not present within this ReturnObjectBag. * * @param key The key for which the next object should be returned. * @return The next object from the ReturnObjectList stored against the given key. * @see ReturnObjectList#nextReturnObject */ public Object getNextReturnObject( Object key ) { if (key == null) { key = Null.NULL; } ReturnObjectList returnObjectList = (ReturnObjectList)returnObjectLists.get(key); AssertMo.assertNotNull(name + " does not contain " + key.toString(), returnObjectList); return returnObjectList.nextReturnObject(); } /** * Returns the next object in the ReturnObjectList for a given int key. * The call will throw an AssertFailError if the requested key is * not present within this ReturnObjectBag. * * @param key The key for which the next object should be returned. * @return The next object from the ReturnObjectList stored against the given key. * @see ReturnObjectList#nextReturnObject */ public Object getNextReturnObject( int key ) { return getNextReturnObject(new Integer(key)); } public Hashtable getHashTable() { return returnObjectLists; } public int getNextReturnInt( Object key ) { return ((Integer)getNextReturnObject(key)).intValue(); } public boolean getNextReturnBoolean( Object key ) { return ((Boolean)getNextReturnObject(key)).booleanValue(); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ReturnValue.java0000644000175000017500000000634410605540372023716 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; /** *

The ReturnValue class allows a value to be setup which will then be returned upon a specific * invokedMethod call. If value.getValue() is called before value.setValue(value) * the ReturnValue will raise an error warning that this value has not been set. If the required * return value is null the return value can be set like this * value.setValue(null) in this case calling value.getValue() * will return null.

*

*

The advantage of this is provide better information to the user of a mock when * interacting with third party code which may expect certain values to have been set.

*

* e.g. *

 * private final ReturnValue value = new ReturnValue("value");
 * 

* public void setupValue(Integer value){ * value.setValue(value); * } *

* public Integer getValue(){ * return (Integer)value.getValue(); * } *

* * @version $Revision: 1.1 $ */ public class ReturnValue { private final String name; private Object value; /** * @param name the name used to identify the ReturnValue when an error is raised */ public ReturnValue( String name ) { this.name = name; } /** * @return the value set using setValue * @throws junit.framework.AssertionFailedError * throw if setValue has not been called */ public Object getValue() { AssertMo.assertNotNull("The return value \"" + name + "\" has not been set.", value); if (value instanceof Null) { return null; } return value; } /** * @param value value to be returned by getValue. null can be use to force getValue to return null. */ public void setValue( Object value ) { if (value == null) { this.value = Null.NULL; } else { this.value = value; } } /** * @param value value to be returned by getBooleanValue. Calling getValue after this invokedMethod will return * a Boolean wrapper around the value. */ public void setValue( boolean value ) { setValue(new Boolean(value)); } /** * @return the current value converted to a boolean */ public boolean getBooleanValue() { return ((Boolean)getValue()).booleanValue(); } /** * @return the current value converted to an int */ public int getIntValue() { return ((Number)getValue()).intValue(); } /** * @param value value to be returned by getIntValue. Calling getValue after this invokedMethod will return * a Integer wrapper around the value. */ public void setValue( int value ) { setValue(new Integer(value)); } /** * @param value value to be returned by getLongValue. Calling getValue after this invokedMethod will return * a Long wrapper around the value. */ public void setValue( long value ) { setValue(new Long(value)); } /** * @return the current value converted to an long */ public long getLongValue() { return ((Number)getValue()).longValue(); } }jmock-1.2.0.orig/jmock-core/org/jmock/expectation/MapEntry.java0000644000175000017500000000521710605540372023177 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.lang.reflect.Array; import java.util.Map; /** * A public MapEntry data type that can be used where the Map.Entry interface is required * (needed because the Sun implementation is package protected) */ public class MapEntry implements Map.Entry { private Object myKey; private Object myValue; public MapEntry( Object aKey, Object aValue ) { myKey = (aKey == null ? new Null() : aKey); myValue = (aValue == null ? new Null() : aValue); } public boolean equals( Object o ) { if (!(o instanceof MapEntry)) { return false; } MapEntry other = (MapEntry)o; if (myValue.getClass().isArray() && other.getValue().getClass().isArray()) { return arrayEquals(other.getValue()); } return myKey.equals(other.getKey()) && myValue.equals(other.getValue()); } private final boolean arrayEquals( Object anArray ) { int i = 0; boolean endOfThisArray = false; boolean endOfAnotherArray = false; while (true) { Object valueOfThis = null; Object valueOfAnother = null; try { valueOfThis = Array.get(myValue, i); } catch (ArrayIndexOutOfBoundsException e) { endOfThisArray = true; } try { valueOfAnother = Array.get(anArray, i); } catch (ArrayIndexOutOfBoundsException e) { endOfAnotherArray = true; } if (endOfThisArray && endOfAnotherArray) { return true; } if (valueOfThis != null || valueOfAnother != null) { if (valueOfThis == null || !valueOfThis.equals(valueOfAnother)) { return false; } } i++; } } public Object getKey() { return myKey; } public Object getValue() { return myValue; } public int hashCode() { int hash = myKey.hashCode(); if (myValue.getClass().isArray()) { for (int i = 0; i < Array.getLength(myValue); i++) { hash = hash ^ Array.get(myValue, i).hashCode(); } } else { hash = hash ^ myValue.hashCode(); } return hash; } public Object setValue( Object aValue ) { Object oldValue = myValue; myValue = (null == aValue ? new Null() : aValue); return oldValue; } public String toString() { return myKey.toString() + "=" + myValue.toString(); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationDoubleValue.java0000644000175000017500000000312610605540372026050 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; public class ExpectationDoubleValue extends AbstractExpectation { private Double expectedValue = null; private double expectedError = 0.0; private boolean expectNothing = false; private Double actualValue = null; public ExpectationDoubleValue( String name ) { super(name); clearActual(); } public void clearActual() { actualValue = null; } public void setActual( double value ) { actualValue = new Double(value); if (shouldCheckImmediately()) { verify(); } } public void setExpected( double value, double error ) { expectedValue = new Double(value); expectedError = Math.abs(error); setHasExpectations(); } public void setExpectNothing() { expectNothing = true; clearActual(); setHasExpectations(); } public void verify() { if (expectNothing) { AssertMo.assertNull(myName + " expected no value", actualValue); } else if (expectedValue != null) { AssertMo.assertNotNull(myName + " expected a value", actualValue); double actualError = Math.abs(actualValue.doubleValue() - expectedValue.doubleValue()); AssertMo.assertTrue(myName + " expected a value within " + expectedError + " of " + expectedValue + ", was " + actualValue, actualError <= expectedError); } } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/VoidReturnValues.java0000644000175000017500000000132510605540372024715 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; /** * Sequence of void values as required by MockMaker * This is a generic class that should have been introduced to the mockobjects code stream instead of * being separately included in org.mockobjects. * It is possibly similar to a ReturnObjectList? */ public class VoidReturnValues extends ReturnValues { public VoidReturnValues( String name, boolean keepUsingLastReturnValue ) { super(name, keepUsingLastReturnValue); } public VoidReturnValues( boolean keepUsingLastReturnValue ) { super(keepUsingLastReturnValue); } public Object getNext() { return myContents.isEmpty() ? null : pop(); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/AbstractExpectation.java0000644000175000017500000000414310605540372025404 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import org.jmock.core.Verifiable; abstract public class AbstractExpectation implements Verifiable, Expectation { protected boolean myFailureModeIsImmediate = true; protected String myName; private boolean myHasExpectations = false; public AbstractExpectation( String name ) { myName = name; } protected void assertEquals( String msg, int expectedValue, int actualValue ) { assertEquals(msg, new Integer(expectedValue), new Integer(actualValue)); } /** * Due to junit Assert being a Singleton implemented with static methods, and java's * unfortunate implementation of class methods (e.g. no late binding) it is * necessary to re-implement this invokedMethod here instead of over-riding failNotEquals */ protected void assertEquals( String msg, Object expectedValue, Object actualValue ) { if (!myHasExpectations) { return; } if (expectedValue == null && actualValue == null) { return; } if (expectedValue != null && expectedValue.equals(actualValue)) { return; } junit.framework.Assert.fail(myName + " " + msg + "\nExpected: " + expectedValue + "\nReceived: " + actualValue); } abstract public void clearActual(); public boolean hasExpectations() { return myHasExpectations; } public void setFailOnVerify() { myFailureModeIsImmediate = false; } protected void setHasExpectations() { clearActual(); myHasExpectations = true; } protected boolean shouldCheckImmediately() { return myFailureModeIsImmediate && myHasExpectations; } public abstract void verify(); } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/Null.java0000644000175000017500000000717110605540372022353 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; /** * A class that represents the null value. * The {@link org.jmock.expectation.Null Null} class is used when an * {@link org.jmock.expectation.Expectation Expectation} is set to expect nothing. *

* Example usage: *

 * public class MockX {
 *    private Expectation... anExpectation = new Expectation...(...);
 * 

* public MockX() { * anExpectation.setExpectNothing(); * } *

* public void setAnExpectation(Object value) { * anExpectation.setExpected(value); * } *

* public void setActual(Object value) { * anExpectation.setActual(value); * } * } *

* The act of calling {@link org.jmock.expectation.Expectation#setExpectNothing() Expectation.setExpectNothing()} * tells the expectation that it should expect no values to change. Since * all {@link org.jmock.expectation.Null Null} objects are equal to themselves, * most expectations set their expected value to an instance of * {@link org.jmock.expectation.Null Null}, and at the same time, set their actual * value to another instance of {@link org.jmock.expectation.Null Null}. * This way, when {@link org.jmock.expectation.Verifiable#verify()} checks * expectations, they will compare two {@link org.jmock.expectation.Null Null} * objects together, which is guaranteed to succeed. * * @author Francois Beausoleil (fbos@users.sourceforge.net) * @version $Id: Null.java,v 1.1 2007/04/06 13:51:54 npryce Exp $ */ public class Null { /** * The default description for all {@link org.jmock.expectation.Null Null} * objects. * This String is equal to "Null". */ public static final String DEFAULT_DESCRIPTION = "Null"; /** * A default {@link org.jmock.expectation.Null Null} object. * Instead of always instantiating new {@link org.jmock.expectation.Null Null} * objects, consider using a reference to this object instead. This way, * the virtual machine will not be taking the time required to instantiate * an object everytime it is required. */ public static final Null NULL = new Null(); /** * The description of this {@link org.jmock.expectation.Null Null} object. */ final private String myDescription; /** * Instantiates a new {@link org.jmock.expectation.Null Null} object with * the default description. * * @see org.jmock.expectation.Null#DEFAULT_DESCRIPTION */ public Null() { this(DEFAULT_DESCRIPTION); } /** * Instantiates a new {@link org.jmock.expectation.Null Null} object and * sets it's description. * * @param description */ public Null( String description ) { super(); myDescription = description; } /** * Determines equality between two objects. * {@link org.jmock.expectation.Null Null} objects are only equal to * another instance of themselves. * * @param other */ public boolean equals( Object other ) { return other instanceof Null; } /** * Returns this {@link org.jmock.expectation.Null Null} object's hashCode. * All {@link org.jmock.expectation.Null Null} return the same * hashCode value. */ public int hashCode() { return 0; } /** * Returns a string representation of this {@link org.jmock.expectation.Null Null} * object. * This merely returns the string passed to the constructor initially. */ public String toString() { return myDescription; } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ReturnObjectList.java0000644000175000017500000000450310605540372024677 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Vector; import org.jmock.core.Verifiable; /** *

This class allows a list of objects to be setup which can be used whilst.The * list is check to make sure that all the object in it are used and that none * are left over at the end of a test.

*

*

For ever sucessive call to nextReturnObject the next object in the list will * returned.

*

*

If the nextReturnObject invokedMethod is called and there are no objects in the list * an assertion error will be thrown. If the verify invokedMethod is called and there * are objects still in the list an assertion error will also be thrown.

*/ public class ReturnObjectList implements Verifiable { private final Vector myObjects = new Vector(); private final String myName; /** * Construct a new empty list * * @param aName Label used to identify list */ public ReturnObjectList( String aName ) { this.myName = aName; } /** * Add a next object to the end of the list. * * @param anObjectToReturn object to be added to the list */ public void addObjectToReturn( Object anObjectToReturn ) { myObjects.add(anObjectToReturn); } /** * Add a next boolean to the end of the list. * * @param aBooleanToReturn boolean to be added to the list */ public void addObjectToReturn( boolean aBooleanToReturn ) { myObjects.add(new Boolean(aBooleanToReturn)); } /** * Add a next integer to the end of the list. * * @param anIntegerToReturn integer to be added to the list */ public void addObjectToReturn( int anIntegerToReturn ) { myObjects.add(new Integer(anIntegerToReturn)); } /** * Returns the next object from the list. Each object it returned in the * order in which they where added. */ public Object nextReturnObject() { AssertMo.assertTrue(myName + " has run out of objects.", myObjects.size() > 0); return myObjects.remove(0); } /** * Verify that there are no objects left within the list. */ public void verify() { AssertMo.assertEquals(myName + " has un-used objects.", 0, myObjects.size()); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationCounter.java0000644000175000017500000000204410605540372025256 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import junit.framework.Assert; public class ExpectationCounter extends AbstractExpectation { private int myExpectedCalls = 0; private int myActualCalls = 0; public ExpectationCounter( String name ) { super(name); } public void clearActual() { myActualCalls = 0; } public void inc() { myActualCalls++; if (shouldCheckImmediately()) { Assert.assertTrue(myName + " should not be called more than " + myExpectedCalls + " times", myActualCalls <= myExpectedCalls); } } public void setExpected( int expectedCalls ) { myExpectedCalls = expectedCalls; setHasExpectations(); } public void setExpectNothing() { myExpectedCalls = 0; setHasExpectations(); } public void verify() { assertEquals("did not receive the expected Count.", myExpectedCalls, myActualCalls); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationValue.java0000644000175000017500000000323510605540372024716 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; public class ExpectationValue extends AbstractExpectation { private Object myExpectedValue; private Object myActualValue; public ExpectationValue( String name ) { super(name); clearActual(); } public void clearActual() { myActualValue = new Null("Nothing"); } public void setActual( int aValue ) { setActual(new Integer(aValue)); } public void setActual( long aValue ) { setActual(new Long(aValue)); } public void setActual( double aValue ) { setActual(new Double(aValue)); } public void setActual( Object aValue ) { myActualValue = aValue; if (shouldCheckImmediately()) { verify(); } } public void setActual( boolean aValue ) { setActual(new Boolean(aValue)); } public void setExpected( int aValue ) { setExpected(new Integer(aValue)); } public void setExpected( long aValue ) { setExpected(new Long(aValue)); } public void setExpected( double aValue ) { setExpected(new Double(aValue)); } public void setExpected( Object aValue ) { myExpectedValue = aValue; setHasExpectations(); } public void setExpected( boolean aValue ) { setExpected(new Boolean(aValue)); } public void setExpectNothing() { setExpected(new Null("Nothing")); myActualValue = myExpectedValue; } public void verify() { assertEquals("did not receive the expected Value.", myExpectedValue, myActualValue); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ReturnObjectMap.java0000644000175000017500000000432210605540372024500 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.Enumeration; import java.util.Hashtable; import org.jmock.core.Verifiable; /** * @version $Revision: 1.1 $ */ public class ReturnObjectMap extends MockObject { private final Hashtable returnValues = new Hashtable(); private final String name; public ReturnObjectMap( String name ) { this.name = name; } public Object getValue( Object key ) { if (key == null) { key = Null.NULL; } AssertMo.assertTrue(name + " does not contain " + key.toString(), returnValues.containsKey(key)); return ((CallCounter)returnValues.get(key)).getValue(); } public Object getValue( short key ) { return getValue(new Short(key)); } public void putReturnValue( Object key, Object value ) { returnValues.put(key != null ? key : Null.NULL, new CallCounter(key, value)); } public void putReturnValue( Object key, int value ) { putReturnValue(key, new Integer(value)); } public void putReturnValue( short key, Object value ) { putReturnValue(new Short(key), value); } public void putReturnValue( Object key, boolean value ) { putReturnValue(key, new Boolean(value)); } public int getIntValue( Object key ) { return ((Integer)getValue(key)).intValue(); } public boolean getBooleanValue( String key ) { return ((Boolean)getValue(key)).booleanValue(); } private class CallCounter implements Verifiable { private int count = 0; private final Object value; private final Object key; public CallCounter( Object key, Object value ) { this.key = key; this.value = value; } public Object getValue() { count++; return value; } public void verify() { AssertMo.assertTrue("Object never called for key: " + key, count > 0); } } public void verify() { super.verify(); for (Enumeration enumeration = returnValues.elements(); enumeration.hasMoreElements();) { ((Verifiable)enumeration.nextElement()).verify(); } } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationSegment.java0000644000175000017500000000223710605540372025245 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; public class ExpectationSegment extends AbstractExpectation { private String myExpectedSegment; private String myActualString; public ExpectationSegment( String name ) { super(name); clearActual(); } public void clearActual() { myActualString = null; } public void setActual( String aString ) { myActualString = aString; if (shouldCheckImmediately()) { verify(); } } public void setExpected( String segment ) { myExpectedSegment = segment; setHasExpectations(); } public void setExpectNothing() { myActualString = null; setExpected(null); } public void verify() { if (hasExpectations()) { if (null == myExpectedSegment) { AssertMo.assertNull("Expecting nothing", myActualString); } else { AssertMo.assertIncludes("Should include string segment", myExpectedSegment, myActualString); } } } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/AssertMo.java0000644000175000017500000000627510605540372023202 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import junit.framework.Assert; import junit.framework.AssertionFailedError; import org.jmock.core.Verifiable; import org.jmock.util.NotImplementedException; public class AssertMo extends Assert { protected AssertMo() { super(); } public static void assertEquals( String description, Object[] expectedArray, Object[] actualArray ) { assertEquals(description + " (different lengths)", expectedArray.length, actualArray.length); for (int i = 0; i < expectedArray.length; i++) { assertEquals(description + " (element " + i + ")", expectedArray[i], actualArray[i]); } } public static void assertExcludes( String description, String excludeString, String targetString ) { assertTrue(description + "\nExclude String: " + excludeString + "\n Target String: " + targetString, targetString.indexOf(excludeString) == -1); } public static void assertIncludes( String description, String includeString, String targetString ) { assertTrue(description + "\nInclude String: " + includeString + "\n Target String: " + targetString, targetString.indexOf(includeString) != -1); } public static void assertStartsWith( String description, String startString, String targetString ) { assertTrue(description + "\n Start String: " + startString + "\nTarget String: " + targetString, targetString.startsWith(startString)); } public static void assertVerifyFails( Verifiable aVerifiable ) { boolean threwException = false; try { aVerifiable.verify(); } catch (AssertionFailedError ex) { threwException = true; } assertTrue("Should not have verified", threwException); } static protected void failNotEquals( String message, Object expected, Object actual ) { String formatted = ""; if (message != null) { formatted = message + " "; } fail(formatted + "\nExpected:<" + expected + ">\nReceived:<" + actual + ">"); } public static void notImplemented( String mockName ) { throw new NotImplementedException("Not Implemented in " + mockName); } public static void assertFails( String message, Runnable runnable ) { try { runnable.run(); } catch (AssertionFailedError expected) { return; } fail(message); } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExpectationList.java0000644000175000017500000000231710605540372024555 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import java.util.ArrayList; import java.util.Collection; import junit.framework.Assert; public class ExpectationList extends AbstractExpectationCollection { protected ArrayList myExpectedItems = new ArrayList(); protected ArrayList myActualItems = new ArrayList(); public ExpectationList( String name ) { super(name); } protected void checkImmediateValues( Object actualItem ) { int size = myActualItems.size(); Assert.assertTrue(myName + " had different sizes\nExpected Size:" + myExpectedItems.size() + "\nReceived size: " + size + " when adding:" + actualItem, myExpectedItems.size() >= size); assertEquals(myName + " added item does not match", myExpectedItems.get(size - 1), actualItem); } protected Collection getActualCollection() { return myActualItems; } protected Collection getExpectedCollection() { return myExpectedItems; } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/ExceptionalReturnValue.java0000644000175000017500000000111310605540372026077 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; /** * Sequence of exception values as required by MockMaker * This is a generic class that should have been introduced to the mockobjects code stream instead of * being separately included in org.mockobjects. * It is possibly similar to a ReturnObjectList? */ public class ExceptionalReturnValue { private Throwable exception; public ExceptionalReturnValue( Throwable exception ) { this.exception = exception; } public Throwable getException() { return exception; } } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/Expectation.java0000644000175000017500000000242410605540372023720 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import org.jmock.core.Verifiable; /** * An Expectation is an object that we set up at the beginning of a unit test to * expect certain things to happen to it. If it is possible to tell, the Expectation will * fail as soon as an incorrect value has been set. *

* Call verify() at the end of a unit test to check for missing or incomplete values. *

* If no expectations have been set on the object, then no checking will be done and * verify() will do nothing. * * @since 1.0 */ public interface Expectation extends Verifiable { /** * Return true if any expectations have been set on this object. */ public boolean hasExpectations(); /** * Tell the object to expect nothing to happen to it, perhaps because the test is exercising * the handling of an error. The Expectation will fail if any actual values are set. *

* Note that this is not the same as not setting any expectations, in which case verify() * will do nothing. */ void setExpectNothing(); /** * If an incorrect actual value is set, defer reporting this as a failure until verify() * is called on this object. */ public void setFailOnVerify(); } jmock-1.2.0.orig/jmock-core/org/jmock/expectation/MockObject.java0000644000175000017500000000213610605540372023455 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock.expectation; import org.jmock.core.Verifiable; import org.jmock.util.Verifier; public abstract class MockObject implements Verifiable { protected void assertEquals( String message, int o1, int o2 ) { AssertMo.assertEquals(message, o1, o2); } protected void assertEquals( String message, Object o1, Object o2 ) { AssertMo.assertEquals(message, o1, o2); } protected void assertTrue( String message, boolean condition ) { AssertMo.assertTrue(message, condition); } protected void fail( String message ) { AssertMo.fail(message); } public void notImplemented() { AssertMo.notImplemented(this.getClass().getName()); } /** * @deprecated */ protected void notYetImplemented() { notYetImplemented(this.getClass().getName()); } /** * @deprecated */ public static void notYetImplemented( String mockName ) { AssertMo.notImplemented(mockName); } public void verify() { Verifier.verifyObject(this); } } jmock-1.2.0.orig/jmock-core/org/jmock/MockObjectTestCase.java0000644000175000017500000001617410606776006022603 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock; import java.util.Collection; import org.jmock.core.CoreMock; import org.jmock.core.DynamicMock; import org.jmock.core.Formatting; import org.jmock.core.Invocation; import org.jmock.core.InvocationMatcher; import org.jmock.core.InvocationMocker; import org.jmock.core.MockObjectSupportTestCase; import org.jmock.core.Stub; import org.jmock.core.matcher.InvokeAtLeastOnceMatcher; import org.jmock.core.matcher.InvokeAtMostOnceMatcher; import org.jmock.core.matcher.InvokeCountMatcher; import org.jmock.core.matcher.InvokeOnceMatcher; import org.jmock.core.matcher.StatelessInvocationMatcher; import org.jmock.core.matcher.TestFailureMatcher; import org.jmock.core.stub.CustomStub; import org.jmock.core.stub.DoAllStub; import org.jmock.core.stub.ReturnIteratorStub; import org.jmock.core.stub.ReturnStub; import org.jmock.core.stub.StubSequence; import org.jmock.core.stub.ThrowStub; import org.jmock.util.NotImplementedException; /** * A base class for tests that use Mock Objects. * This class provides methods for creating mock objects and expectations and automatically * verifying mock objects after the test has run but before the test fixture has been torn down. * * @since 1.0.0 */ public abstract class MockObjectTestCase extends MockObjectSupportTestCase { public MockObjectTestCase() { } public MockObjectTestCase( String name ) { super(name); } /** * Creates a mock object that mocks the given type. The mock object is named after the type; the exact * name is calculated by {@link #defaultMockNameForType}. * * @param mockedType The type to be mocked. * @return A {@link Mock} object that mocks mockedType. */ public Mock mock( Class mockedType ) { return mock(mockedType, defaultMockNameForType(mockedType)); } /** * Creates a mock object that mocks the given type and is explicitly given a name. * The mock object is named after the type; the exact name is calculated by {@link #defaultMockNameForType}. * * @param mockedType The type to be mocked. * @param roleName The name of the mock object * @return A {@link Mock} object that mocks mockedType. */ public Mock mock( Class mockedType, String roleName ) { Mock newMock = new Mock(newCoreMock(mockedType, roleName)); registerToVerify(newMock); return newMock; } protected DynamicMock newCoreMock( Class mockedType, String roleName ) { return new CoreMock(mockedType, roleName); } public Object newDummy(Class dummyType) { return newDummy(dummyType, "dummy" + Formatting.classShortName(dummyType)); } public Object newDummy( final Class type, final String name ) { DynamicMock mock = newCoreMock(type, name); InvocationMocker mocker = new InvocationMocker(); mocker.addMatcher(new StatelessInvocationMatcher() { public boolean matches( Invocation invocation ) { return invocation.invokedMethod.getDeclaringClass() == type; } public StringBuffer describeTo( StringBuffer buf ) { return buf.append("any invokedMethod declared in " + type); } }); mocker.setStub(new CustomStub("dummy invokedMethod") { public Object invoke( Invocation invocation ) throws Throwable { throw new NotImplementedException(invocation.invokedMethod.getName() + " called on " + name); } }); mock.addInvokable(mocker); return mock.proxy(); } public Object newDummy(final String name) { return new Object() { public String toString() { return name; } }; } /** * Calculates * @param mockedType * @return mock name */ public String defaultMockNameForType( Class mockedType ) { return "mock" + Formatting.classShortName(mockedType); } public Stub returnValue( Object o ) { return new ReturnStub(o); } public Stub returnValue( boolean result ) { return returnValue(new Boolean(result)); } public Stub returnValue( byte result ) { return returnValue(new Byte(result)); } public Stub returnValue( char result ) { return returnValue(new Character(result)); } public Stub returnValue( short result ) { return returnValue(new Short(result)); } public Stub returnValue( int result ) { return returnValue(new Integer(result)); } public Stub returnValue( long result ) { return returnValue(new Long(result)); } public Stub returnValue( float result ) { return returnValue(new Float(result)); } public Stub returnValue( double result ) { return returnValue(new Double(result)); } public Stub returnIterator(Collection collection) { return new ReturnIteratorStub(collection); } public Stub returnIterator(Object[] array) { return new ReturnIteratorStub(array); } public Stub throwException( Throwable throwable ) { return new ThrowStub(throwable); } public InvocationMatcher once() { return new InvokeOnceMatcher(); } public InvocationMatcher atLeastOnce() { return new InvokeAtLeastOnceMatcher(); } public InvocationMatcher atMostOnce() { return new InvokeAtMostOnceMatcher(); } public InvocationMatcher exactly( int expectedCount ) { return new InvokeCountMatcher(expectedCount); } public InvocationMatcher never() { return new TestFailureMatcher("not expected"); } public InvocationMatcher never( String errorMessage ) { return new TestFailureMatcher("not expected ("+errorMessage+")"); } /** * @since 1.0.1 */ public Stub onConsecutiveCalls( Stub stub1, Stub stub2 ) { return onConsecutiveCalls(new Stub[]{stub1, stub2}); } /** * @since 1.0.1 */ public Stub onConsecutiveCalls( Stub stub1, Stub stub2, Stub stub3 ) { return onConsecutiveCalls(new Stub[]{stub1, stub2, stub3}); } /** * @since 1.0.1 */ public Stub onConsecutiveCalls( Stub stub1, Stub stub2, Stub stub3, Stub stub4 ) { return onConsecutiveCalls(new Stub[]{stub1, stub2, stub3, stub4}); } /** * @since 1.1.0 */ public Stub onConsecutiveCalls( Stub[] stubs ) { return new StubSequence(stubs); } /** * @since 1.1.0 */ public Stub doAll(Stub stub1, Stub stub2) { return doAll(new Stub[]{stub1, stub2}); } /** * @since 1.1.0 */ public Stub doAll(Stub stub1, Stub stub2, Stub stub3) { return doAll(new Stub[]{stub1, stub2, stub3}); } /** * @since 1.1.0 */ public Stub doAll(Stub stub1, Stub stub2, Stub stub3, Stub stub4) { return doAll(new Stub[]{stub1, stub2, stub3, stub4}); } /** * @since 1.1.0 */ public Stub doAll(Stub[] stubs) { return new DoAllStub(stubs); } } jmock-1.2.0.orig/jmock-core/org/jmock/Mock.java0000644000175000017500000000552410605540410020000 0ustar tonytony/* Copyright (c) 2000-2004 jMock.org */ package org.jmock; import java.util.HashMap; import junit.framework.AssertionFailedError; import org.jmock.builder.BuilderNamespace; import org.jmock.builder.IdentityBuilder; import org.jmock.builder.InvocationMockerBuilder; import org.jmock.builder.InvocationMockerDescriber; import org.jmock.builder.MatchBuilder; import org.jmock.builder.NameMatchBuilder; import org.jmock.core.CoreMock; import org.jmock.core.DynamicMock; import org.jmock.core.InvocationMatcher; import org.jmock.core.InvocationMocker; import org.jmock.core.Invokable; import org.jmock.core.Stub; /** * @since 1.0 */ public class Mock implements DynamicMock, BuilderNamespace { DynamicMock coreMock; HashMap idTable = new HashMap(); public Mock( Class mockedType ) { this(mockedType, CoreMock.mockNameFromClass(mockedType)); } public Mock( Class mockedType, String name ) { this(new CoreMock(mockedType, name)); } public Mock( DynamicMock coreMock ) { this.coreMock = coreMock; } public Class getMockedType() { return coreMock.getMockedType(); } public Object proxy() { return coreMock.proxy(); } public String toString() { return coreMock.toString(); } public void verify() { coreMock.verify(); } public void addInvokable( Invokable invokable ) { coreMock.addInvokable(invokable); } public NameMatchBuilder stubs() { return addNewInvocationMocker(); } public NameMatchBuilder expects( InvocationMatcher expectation ) { NameMatchBuilder builder = addNewInvocationMocker(); builder.match(expectation); return builder; } private NameMatchBuilder addNewInvocationMocker() { InvocationMocker mocker = new InvocationMocker(new InvocationMockerDescriber()); addInvokable(mocker); return new InvocationMockerBuilder( mocker, this, getMockedType() ); } public void setDefaultStub( Stub newDefaultStub ) { coreMock.setDefaultStub(newDefaultStub); } public void reset() { idTable.clear(); coreMock.reset(); } public MatchBuilder lookupID( String id ) { if (!idTable.containsKey(id)) { throw new AssertionFailedError("no expected invocation named '" + id + "'"); } return (MatchBuilder)idTable.get(id); } public void registerUniqueID( String id, MatchBuilder builder ) { if (idTable.containsKey(id)) { throw new AssertionFailedError("duplicate invocation named \"" + id + "\""); } storeID(id, builder); } public void registerMethodName( String id, MatchBuilder builder ) { storeID(id, builder); } private void storeID( String id, IdentityBuilder builder ) { idTable.put(id, builder); } }