jmock-1.2.0.orig/ 0000755 0001750 0001750 00000000000 11636534756 012340 5 ustar tony tony jmock-1.2.0.orig/jmock-cglib/ 0000755 0001750 0001750 00000000000 11636534756 014521 5 ustar tony tony jmock-1.2.0.orig/jmock-cglib/LICENSE.txt 0000644 0001750 0001750 00000002663 07762452754 016355 0 ustar tony tony Copyright (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/ 0000755 0001750 0001750 00000000000 10607017650 015643 5 ustar tony tony jmock-1.2.0.orig/jmock-cglib/META-INF/MANIFEST.MF 0000644 0001750 0001750 00000000152 10607017646 017300 0 ustar tony tony Manifest-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/ 0000755 0001750 0001750 00000000000 10607017644 015275 5 ustar tony tony jmock-1.2.0.orig/jmock-cglib/org/jmock/ 0000755 0001750 0001750 00000000000 10607017646 016402 5 ustar tony tony jmock-1.2.0.orig/jmock-cglib/org/jmock/cglib/ 0000755 0001750 0001750 00000000000 10607017646 017462 5 ustar tony tony jmock-1.2.0.orig/jmock-cglib/org/jmock/cglib/MockObjectTestCase.java 0000644 0001750 0001750 00000002560 10605540412 023772 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000005577 10606735326 022607 0 ustar tony tony /* 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/ 0000755 0001750 0001750 00000000000 11636534756 014371 5 ustar tony tony jmock-1.2.0.orig/jmock-core/LICENSE.txt 0000644 0001750 0001750 00000002663 07762452754 016225 0 ustar tony tony Copyright (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/ 0000755 0001750 0001750 00000000000 10607017650 015513 5 ustar tony tony jmock-1.2.0.orig/jmock-core/META-INF/MANIFEST.MF 0000644 0001750 0001750 00000000152 10607017646 017150 0 ustar tony tony Manifest-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/ 0000755 0001750 0001750 00000000000 10607017644 015145 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/ 0000755 0001750 0001750 00000000000 10607017646 016252 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/util/ 0000755 0001750 0001750 00000000000 10607017646 017227 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/util/Verifier.java 0000644 0001750 0001750 00000005264 10605540406 021645 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000003415 10606776010 021164 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000002332 10605540406 022545 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001034 10605540406 024664 0 ustar tony tony /* 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/ 0000755 0001750 0001750 00000000000 10607017646 017202 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/core/InvocationDispatcher.java 0000644 0001750 0001750 00000000527 10605540374 024166 0 ustar tony tony /* 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/ 0000755 0001750 0001750 00000000000 10607017646 020157 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/core/stub/ReturnIteratorStub.java 0000644 0001750 0001750 00000001770 10605540400 024641 0 ustar tony tony package 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.java 0000644 0001750 0001750 00000003470 10605540400 022752 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000006300 10605540400 024425 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001561 10605540400 023120 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000000666 10605540400 022554 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001430 10605540400 022634 0 ustar tony tony package 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.java 0000644 0001750 0001750 00000002017 10605540400 023413 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001176 10605540400 024077 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001105 10605540400 023117 0 ustar tony tony /* 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/ 0000755 0001750 0001750 00000000000 10607017646 020625 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/core/matcher/InvokeAtMostOnceMatcher.java 0000644 0001750 0001750 00000001077 10605540412 026157 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000002417 10605540412 024547 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001134 10605540412 025021 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000000753 10605540412 025231 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000000761 10605540412 026767 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001674 10605540412 025013 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001505 10605540412 025212 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001002 10605540412 026271 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000002303 10605540412 025341 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000000717 10605540412 025404 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001467 10605540412 025236 0 ustar tony tony package 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.java 0000644 0001750 0001750 00000002214 10605540412 024726 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000006370 10605540374 023322 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000000453 10605540374 021756 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000002264 10605540374 023256 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000004171 10605540374 025651 0 ustar tony tony package 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.java 0000644 0001750 0001750 00000001532 10605540374 020760 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000013076 10606773326 023741 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000000747 10605540374 022176 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000006127 10605540374 022162 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001335 10605540374 024636 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000022101 10606776006 025113 0 ustar tony tony /* 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/ 0000755 0001750 0001750 00000000000 10607017646 021366 5 ustar tony tony jmock-1.2.0.orig/jmock-core/org/jmock/core/constraint/SubstringConstraint.java 0000644 0001750 0001750 00000001426 10605540372 026254 0 ustar tony tony package 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.java 0000644 0001750 0001750 00000001266 10605540374 024733 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000003222 10605540372 023566 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001114 10605540372 023255 0 ustar tony tony /* 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.java 0000644 0001750 0001750 00000001446 10605540374 023414 0 ustar tony tony /* 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.html 0000644 0001750 0001750 00000000361 10605540372 023642 0 ustar tony tony
A collection of commonly useful constraints
@see org.jmock.core.Constraint @since 1.0