You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(151) |
Sep
(21) |
Oct
(6) |
Nov
(70) |
Dec
(8) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(47) |
Feb
(66) |
Mar
(23) |
Apr
(115) |
May
(24) |
Jun
(53) |
Jul
(10) |
Aug
(279) |
Sep
(84) |
Oct
(149) |
Nov
(138) |
Dec
(52) |
2003 |
Jan
(22) |
Feb
(20) |
Mar
(29) |
Apr
(106) |
May
(170) |
Jun
(122) |
Jul
(70) |
Aug
(64) |
Sep
(27) |
Oct
(71) |
Nov
(49) |
Dec
(9) |
2004 |
Jan
(7) |
Feb
(38) |
Mar
(3) |
Apr
(9) |
May
(22) |
Jun
(4) |
Jul
(1) |
Aug
(2) |
Sep
(2) |
Oct
|
Nov
(15) |
Dec
(2) |
2005 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(28) |
Jun
(3) |
Jul
(11) |
Aug
(5) |
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2006 |
Jan
(8) |
Feb
(3) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Steve F. <sm...@us...> - 2002-10-21 22:55:38
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv15550/src/jdk/common/test/mockobjects Added Files: TestExpectationSqlRow.java Log Message: moved jdk-specific test --- NEW FILE: TestExpectationSqlRow.java --- package test.mockobjects; import com.mockobjects.sql.ExpectationSqlRow; import com.mockobjects.util.TestCaseMo; import junit.framework.AssertionFailedError; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; public class TestExpectationSqlRow extends TestCaseMo { private static final Class THIS = TestExpectationSqlRow.class; private ExpectationSqlRow row = new ExpectationSqlRow("sql row"); public TestExpectationSqlRow(String name) { super(name); } public void testIndexedValues() throws SQLException { row.addExpectedIndexedValues(new Object[] { "one", "two" }); assertEquals("should have value", "one", row.get(1)); assertEquals("should have value", "two", row.get(2)); row.verify(); } public void testConstructorIndexedValues() throws SQLException { ExpectationSqlRow aRow = new ExpectationSqlRow("row1", new Object[] { "one", "two" }); assertEquals("should have value", "one", aRow.get(1)); assertEquals("should have value", "two", aRow.get(2)); aRow.verify(); } public void testNamedValues() throws SQLException { row.addExpectedNamedValues( new String[] {"col1", "col2" }, new Object[] {"one", "two" }); assertEquals("should have value", "two", row.get("col2")); assertEquals("should have value", "one", row.get("col1")); row.verify(); } public void testConstructorNamedValues() throws SQLException { ExpectationSqlRow aRow = new ExpectationSqlRow("row1", new String[] {"col1", "col2" }, new Object[] { "one", "two" }); assertEquals("should have value", "two", aRow.get("col2")); assertEquals("should have value", "one", aRow.get("col1")); aRow.verify(); } public void testNamedValuesFromMap() throws SQLException { Map values = new HashMap(); values.put("col1", "one"); values.put("col2", "two"); row.addExpectedNamedValues(values); assertEquals("should have value", "two", row.get("col2")); assertEquals("should have value", "one", row.get("col1")); row.verify(); } public void testNoValues() { row.verify(); } public void testFailInvalidIndex() throws SQLException { row.addExpectedIndexedValues(new Object[] { "one" }); boolean assertionFailed = false; try { row.get(3); } catch (AssertionFailedError ex) { assertionFailed = true; } assertTrue("Should have failed", assertionFailed); } public void testFailInvalidKey() throws SQLException { row.addExpectedNamedValues(new String[] {"col1" }, new Object[] {"one" }); boolean assertionFailed = false; try { row.get("col2"); } catch (AssertionFailedError ex) { assertionFailed = true; } assertTrue("Should have failed", assertionFailed); } public void testFailEmptyRow() throws SQLException { boolean assertionFailed = false; try { row.get(1); } catch (AssertionFailedError ex) { assertionFailed = true; } assertTrue("Should have failed", assertionFailed); } public void testIndexNotGot() throws SQLException { row.addExpectedIndexedValues(new Object[] { "one" }); boolean assertionFailed = false; try { row.verify(); } catch (AssertionFailedError ex) { assertionFailed = true; } assertTrue("Should have failed", assertionFailed); } public void testThrowExceptionOnGet() { row.addExpectedIndexedValues(new Object[] {new SQLException("Mock SQL Excpeption")}); try { row.get(1); fail("Should have thrown exception"); } catch (SQLException expected) { } } } |
From: Steve F. <sm...@us...> - 2002-10-21 22:55:11
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv14997/src/jdk/1.4/test/mockobjects Added Files: Test_Matches.java Log Message: added 1.4-specific dynamic class and test --- NEW FILE: Test_Matches.java --- /* * Date: 21-Oct-2002 */ package test.mockobjects; import com.mockobjects.dynamic.Matches; import com.mockobjects.dynamic.Predicate; import junit.framework.TestCase; public class Test_Matches extends TestCase { public Test_Matches(String name) { super(name); } public void testMatches() { Predicate p = new Matches("^hello, (.*)\\.$"); assertTrue(p.eval("hello, world.")); assertTrue(p.eval("hello, mum.")); assertTrue(!p.eval("hello world.")); assertTrue(!p.eval("hello, world")); assertTrue(!p.eval("goodbye, world.")); } } |
From: Steve F. <sm...@us...> - 2002-10-21 22:55:11
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv14997/src/jdk/1.4/com/mockobjects/dynamic Added Files: Matches.java Log Message: added 1.4-specific dynamic class and test --- NEW FILE: Matches.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; import java.util.regex.Matcher; import java.util.regex.Pattern; /** Is the argument a string that matches a regular expression? */ public class Matches implements Predicate { private Pattern _pattern; private Matcher _matcher; /** Creates a new instance of IsEqual */ public Matches( String regex ) { _pattern = Pattern.compile(regex); } public boolean eval( Object arg ) { if( arg instanceof String ) { Matcher matcher = _pattern.matcher((String)arg); return matcher.matches(); } else { return false; } } public String toString() { return "a string that matches <" + _pattern.toString() + ">"; } } |
From: Steve F. <sm...@us...> - 2002-10-21 22:54:19
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv13978/src/jdk/common/test/mockobjects Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/common/test/mockobjects added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:54:19
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/test In directory usw-pr-cvs1:/tmp/cvs-serv13978/src/jdk/common/test Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/common/test added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:53:48
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv13396/src/jdk/1.4/test/mockobjects Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test/mockobjects added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:53:48
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test In directory usw-pr-cvs1:/tmp/cvs-serv13396/src/jdk/1.4/test Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/test added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:53:32
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv13088/src/jdk/1.4/com/mockobjects/dynamic Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/jdk/1.4/com/mockobjects/dynamic added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:53:22
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet In directory usw-pr-cvs1:/tmp/cvs-serv12890/src/j2ee/common/com/mockobjects/servlet Modified Files: MockRequestDispatcher.java Log Message: fixed interface bug Index: MockRequestDispatcher.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/servlet/MockRequestDispatcher.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockRequestDispatcher.java 20 Jun 2002 11:51:24 -0000 1.2 +++ MockRequestDispatcher.java 21 Oct 2002 22:53:19 -0000 1.3 @@ -13,7 +13,7 @@ private final ExpectationValue myRequest = new ExpectationValue("request"); private final ExpectationValue myResponse = new ExpectationValue("response"); - public void setExpectedRequest(ServletResponse aRequest){ + public void setExpectedRequest(ServletRequest aRequest){ myRequest.setExpected(aRequest); } |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/test In directory usw-pr-cvs1:/tmp/cvs-serv12447/src/core/com/mockobjects/test Removed Files: TestReturnObjectList.java TestExpectationMap.java AllTests.java TestExpectationSqlRow.java TestVerifier.java TestExpectationValue.java TestExpectationDoubleValue.java TestNull.java TestExpectationCollection.java TestExpectationCounter.java TestExpectationSegment.java TestMapEntry.java TestExpectationSet.java TestExpectationList.java TestAssertMo.java Log Message: moved test classes to a new package --- TestReturnObjectList.java DELETED --- --- TestExpectationMap.java DELETED --- --- AllTests.java DELETED --- --- TestExpectationSqlRow.java DELETED --- --- TestVerifier.java DELETED --- --- TestExpectationValue.java DELETED --- --- TestExpectationDoubleValue.java DELETED --- --- TestNull.java DELETED --- --- TestExpectationCollection.java DELETED --- --- TestExpectationCounter.java DELETED --- --- TestExpectationSegment.java DELETED --- --- TestMapEntry.java DELETED --- --- TestExpectationSet.java DELETED --- --- TestExpectationList.java DELETED --- --- TestAssertMo.java DELETED --- |
From: Steve F. <sm...@us...> - 2002-10-21 22:52:41
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv11992/src/core/test/mockobjects/dynamic Added Files: Test_Predicates.java Test_Mock.java Log Message: moved test classes to a new package --- NEW FILE: Test_Predicates.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:24 PM */ package test.mockobjects.dynamic; import com.mockobjects.dynamic.*; import java.util.EventObject; public class Test_Predicates extends junit.framework.TestCase { class True implements Predicate { public boolean eval( Object o ) { return true; } } class False implements Predicate { public boolean eval( Object o ) { return false; } } /** Creates a new instance of Test_Predicates */ public Test_Predicates( String test ) { super(test); } public void testIsNull() { Predicate p = new IsNull(); assertTrue( p.eval(null) ); assertTrue( !p.eval(new Object()) ); } public void testIsSame() { Object o1 = new Object(); Object o2 = new Object(); Predicate p = new IsSame(o1); assertTrue( p.eval(o1) ); assertTrue( !p.eval(o2) ); } public void testIsEqual() { Integer i1 = new Integer(1); Integer i2 = new Integer(2); Predicate p = new IsEqual(i1); assertTrue( p.eval(i1) ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( !p.eval(i2) ); } public void testIsGreaterThan() { Predicate p = new IsGreaterThan( new Integer(1) ); assertTrue( !p.eval( new Integer(0) ) ); assertTrue( !p.eval( new Integer(1) ) ); assertTrue( p.eval( new Integer(2) ) ); } public void testIsLessThan() { Predicate p = new IsLessThan( new Integer(1) ); assertTrue( p.eval( new Integer(0) ) ); assertTrue( !p.eval( new Integer(1) ) ); assertTrue( !p.eval( new Integer(2) ) ); } public void testIsAnything() { Predicate p = new IsAnything(); assertTrue( p.eval(null) ); assertTrue( p.eval( new Object() ) ); } public void testIsInstanceOf() { Predicate p = new IsInstanceOf( Number.class ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( p.eval( new Double(1.0) ) ); assertTrue( !p.eval("a string") ); assertTrue( !p.eval(null) ); } public void testIsNot() { Predicate p = new IsNot( new True() ); assertTrue( !p.eval(null) ); assertTrue( !p.eval( new Object() ) ); } public void testAnd() { Object o = new Object(); assertTrue( new And( new True(), new True() ).eval(o) ); assertTrue( !new And( new False(), new True() ).eval(o) ); assertTrue( !new And( new True(), new False() ).eval(o) ); assertTrue( !new And( new False(), new False() ).eval(o) ); } public void testOr() { Object o = new Object(); assertTrue( new Or( new True(), new True() ).eval(o) ); assertTrue( new Or( new False(), new True() ).eval(o) ); assertTrue( new Or( new True(), new False() ).eval(o) ); assertTrue( !new Or( new False(), new False() ).eval(o) ); } public void testIsEventFrom() { Object o = new Object(); EventObject ev = new EventObject(o); EventObject ev2 = new EventObject( new Object() ); Predicate p = new IsEventFrom(o); assertTrue( p.eval(ev) ); assertTrue( "p should eval to false for an event not from o", !p.eval(ev2) ); assertTrue( "p should eval to false for objects that are not events", !p.eval(o) ); } private static class DerivedEvent extends EventObject { public DerivedEvent( Object source ) { super(source); } } public void testIsEventSubtypeFrom() { Object o = new Object(); DerivedEvent good_ev = new DerivedEvent(o); DerivedEvent wrong_source = new DerivedEvent(new Object()); EventObject wrong_type = new EventObject(o); EventObject wrong_source_and_type = new EventObject(new Object()); Predicate p = new IsEventFrom( DerivedEvent.class, o ); assertTrue( p.eval(good_ev) ); assertTrue( "p should eval to false for an event not from o", !p.eval(wrong_source) ); assertTrue( "p should eval to false for an event of the wrong type", !p.eval(wrong_type) ); assertTrue( "p should eval to false for an event of the wrong type "+ "and from the wrong source", !p.eval(wrong_source_and_type) ); } public void testIsCloseTo() { Predicate p = new IsCloseTo( 1.0, 0.5 ); assertTrue( p.eval( new Double(1.0) ) ); assertTrue( p.eval( new Double(0.5) ) ); assertTrue( p.eval( new Double(1.5) ) ); assertTrue( p.eval( new Float(1.0) ) ); assertTrue( p.eval( new Integer(1) ) ); assertTrue( "number too large", !p.eval( new Double(2.0) ) ); assertTrue( "number too small", !p.eval( new Double(0.0) ) ); try { p.eval("wrong type"); fail("ClassCastException expected for wrong type of argument"); } catch( ClassCastException ex ) { // expected } } } --- NEW FILE: Test_Mock.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 11, 2002, 12:34 AM */ package test.mockobjects.dynamic; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import junit.framework.AssertionFailedError; import com.mockobjects.dynamic.*; public class Test_Mock extends junit.framework.TestCase { public static interface ExampleInterface { Object noArgs(); void voidMethod(); String objectTypes( Integer i ); int primitiveTypes( int x, int y ); void sideEffect( StringBuffer buf ); // These are used to test default return values boolean booleanResult(); byte byteResult(); char charResult(); short shortResult(); int intResult(); long longResult(); float floatResult(); double doubleResult(); String stringResult(); // Used to test ordered calls void first(); void second(); } public static class DerivedMock extends Mock { DerivedMock( String name ) { super(name); } public boolean was_called = false; public void voidMethod() { this.was_called = true; } public String objectTypes( Integer n ) throws Throwable { Method method = getClass().getMethod("objectTypes", new Class[] { Integer.class } ); return (String)mockCall( method , new Object[]{n} ); } }; private Mock _mock; private ExampleInterface _interface; public Test_Mock( String test ) { super(test); } public void setUp() { _mock = new Mock(); _interface = (ExampleInterface)_mock.createInterface( ExampleInterface.class ); } public void tearDown() { _mock = null; _interface = null; } public void testNewMockVerifies() { _mock.verify(); } public void testNamedMock() { Mock mock = new Mock("Name"); assertEquals( "Name", mock.toString() ); } public void testMockCallToNoArgMethod() { Object result = new Object(); _mock.expectReturn( "noArgs", Mock.NO_ARGS, result ); assertSame( result, _interface.noArgs() ); _mock.verify(); } public void testMockCallToVoidMethod() { _mock.expectVoid( "voidMethod", Mock.NO_ARGS ); _interface.voidMethod(); _mock.verify(); } public void testObjectTypes() { _mock.expectReturn( "objectTypes", new Predicate[] { new IsEqual( new Integer(1) ) }, "1" ); assertEquals( "1", _interface.objectTypes( new Integer(1) ) ); _mock.verify(); } public void testPrimitiveTypes() { _mock.expectReturn( "primitiveTypes", new Predicate[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new Integer(6) ); assertEquals( 6, _interface.primitiveTypes(2,3) ); _mock.verify(); } public void testLaterExpectationsOverrideEarlierExpectations() { Object result1 = new Object(); Object result2 = new Object(); _mock.expectReturn( "noArgs", Mock.NO_ARGS, result1 ); _mock.expectReturn( "noArgs", Mock.NO_ARGS, result2 ); assertSame( result2, _interface.noArgs() ); assertSame( result2, _interface.noArgs() ); _mock.verify(); } public void testThrow() { _mock.expectThrow( "primitiveTypes", new Predicate[] { new IsEqual( new Integer(2) ), new IsEqual( new Integer(3) ) }, new ArithmeticException("message") ); try { _interface.primitiveTypes( 2, 3 ); fail( "expected ArithmeticException to be thrown" ); } catch( ArithmeticException ex ) { assertEquals( "message", ex.getMessage() ); } _mock.verify(); } public void testExpectCallWithSideEffects() { final StringBuffer buf = new StringBuffer(); _mock.expect( new ExpectedCall( "sideEffect", new Predicate[]{ new IsSame(buf) } ) { public Object eval( Object[] args ) throws Throwable { buf.append("hello"); return null; } } ); _interface.sideEffect( buf ); assertEquals( "hello", buf.toString() ); _mock.verify(); } public void testNotAllMethodsCalled() { _mock.expectVoid( "noArgs", Mock.NO_ARGS ); try { _mock.verify(); } catch( AssertionFailedError ex ) { return; } fail( "verify did not fail when all expected methods were not called" ); } public void testCalledExpectationClearedBySubsequentExpecation() { _mock.expectVoid( "noArgs", Mock.NO_ARGS ); _interface.noArgs(); _mock.expectVoid( "noArgs", Mock.NO_ARGS ); try { _mock.verify(); } catch( AssertionFailedError ex ) { return; } fail( "verify did not fail when all expected methods were not called" ); } public void testUnexpectedMethodThrowsWhenStrict() { _mock.setStrict(true); try { _interface.voidMethod(); } catch( AssertionFailedError ex ) { return; } fail( "strict mock did not fail when unexpected method was called" ); } public void testUnexpectedMethodDoesNotThrowWhenNotStrict() { try { _interface.voidMethod(); } catch( AssertionFailedError ex ) { fail( "unstrict mock failed when unexpected method was called" ); } } public void testDefaultResultFromUnexpectedCalls() { assertEquals( false, _interface.booleanResult() ); assertEquals( 0, _interface.byteResult() ); assertEquals( '\0', _interface.charResult() ); assertEquals( 0, _interface.shortResult() ); assertEquals( 0, _interface.intResult() ); assertEquals( 0L, _interface.longResult() ); assertEquals( 0.0f, _interface.floatResult(), 0.0f ); assertEquals( 0.0d, _interface.doubleResult(), 0.0d ); assertEquals( "", _interface.stringResult() ); } public void testSetupDefaultResult() { _mock.setupDefaultResult( boolean.class, new Boolean(true) ); _mock.setupDefaultResult( byte.class, new Byte((byte)1) ); _mock.setupDefaultResult( char.class, new Character( '2' ) ); _mock.setupDefaultResult( short.class, new Short( (short)3 ) ); _mock.setupDefaultResult( int.class, new Integer(4) ); _mock.setupDefaultResult( long.class, new Long(5L) ); _mock.setupDefaultResult( float.class, new Float(6.0f) ); _mock.setupDefaultResult( double.class, new Double(7.0d) ); _mock.setupDefaultResult( String.class, "8" ); assertEquals( true, _interface.booleanResult() ); assertEquals( (byte)1, _interface.byteResult() ); assertEquals( '2', _interface.charResult() ); assertEquals( 3, _interface.shortResult() ); assertEquals( 4, _interface.intResult() ); assertEquals( 5L, _interface.longResult() ); assertEquals( 6.0f, _interface.floatResult(), 0.0f ); assertEquals( 7.0d, _interface.doubleResult(), 0.0d ); assertEquals( "8", _interface.stringResult() ); } public void testWrongNumberOfArguments() { Predicate p = new IsEqual( new Integer(2) ); Predicate q = new IsAnything(); _mock.expectReturn( "objectTypes", new Predicate[]{p,q}, "2" ); try { _interface.objectTypes( new Integer(1) ); } catch( AssertionFailedError ex ) { return; } fail( "mock did not fail when wrong number of arguments passed" ); } public void testArgumentsPassedToNoArgMethod() { Predicate p = new IsAnything(); _mock.expectVoid( "voidMethod", new Predicate[]{p} ); try { _interface.voidMethod(); } catch( AssertionFailedError ex ) { return; } fail( "mock did not fail when arguments passed to void method" ); } public void testPredicateFailure() { Predicate p = new IsEqual( new Integer(2) ); _mock.expectReturn( "objectTypes", new Predicate[]{p}, "2" ); assertTrue( !p.eval( new Integer(1) ) ); try { _interface.objectTypes( new Integer(1) ); } catch( AssertionFailedError ex ) { return; } fail( "mock did not fail when predicate returned false" ); } public void testErrorWhenOrderedMethodsCalledInWrongOrder() { _mock.expectVoid( "first", Mock.NO_ARGS ); _mock.expectVoid( "second", Mock.NO_ARGS ); _mock.order( "first", "second" ); try { _interface.second(); } catch( AssertionFailedError ex ) { return; } fail( "mock did not enforce order of calls" ); } public void testExpectNotCalled() { _mock.expectNotCalled("noArgs"); try { _interface.noArgs(); } catch( AssertionFailedError ex ) { return; } fail("AssertionFailedError expected"); } public void testExpectNotCalledClearedBySubsequentExpectation() { _mock.expectNotCalled("noArgs"); _mock.expectVoid( "noArgs", Mock.NO_ARGS ); _interface.noArgs(); _mock.verify(); } public void testSetupResult() { final String RESULT = "result"; _mock.setupResult( "objectTypes", RESULT ); assertEquals( RESULT, _interface.objectTypes(null) ); assertEquals( RESULT, _interface.objectTypes(new Integer(0)) ); _mock.verify(); } public void testSetupThrow() { _mock.setupThrow( "objectTypes", new IllegalArgumentException() ); try { _interface.objectTypes(null); fail("expected IllegalArgumentException"); } catch( IllegalArgumentException ex ) { // expected } try { _interface.objectTypes(new Integer(0)); fail("expected IllegalArgumentException"); } catch( IllegalArgumentException ex ) { // expected } _mock.verify(); } public void testSetupCallWithSideEffect() { final StringBuffer buf = new StringBuffer(); _mock.setup( new ExpectedCall("sideEffect") { public Object eval( Object[] args ) throws Throwable { buf.append("hello"); return null; } } ); _interface.sideEffect( buf ); assertEquals( "hello", buf.toString() ); _mock.verify(); } public void testSetupResultDoesNotRequireCall() { _mock.setupResult( "objectTypes", "result" ); _mock.verify(); } public void testSetupThrowDoesNotRequireCall() { _mock.setupThrow( "objectTypes", new RuntimeException() ); _mock.verify(); } public void testSetupCallWithSideEffectDoesNotRequireCall() { _mock.setup( new ExpectedCall("sideEffect") { public Object eval( Object[] args ) throws Throwable { throw new RuntimeException("should not be called"); } } ); _mock.verify(); } public void testNoErrorWhenOrderedMethodsCalledInCorrectOrder() { _mock.expectVoid( "first", Mock.NO_ARGS ); _mock.expectVoid( "second", Mock.NO_ARGS ); _mock.order( "first", "second" ); _interface.first(); _interface.second(); } public void testDerivedMockClass() { DerivedMock mock = new DerivedMock("Derived"); ExampleInterface i = (ExampleInterface)Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{ ExampleInterface.class }, mock ); i.voidMethod(); assertTrue( "mock method not called on derived class", mock.was_called ); mock.verify(); } public void testDerivedClassPassingInvocationToMockCall() { DerivedMock mock = new DerivedMock("Derived"); ExampleInterface i = (ExampleInterface)Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{ ExampleInterface.class }, mock ); mock.expectReturn( "objectTypes", new Predicate[] { new IsAnything() }, "result" ); assertEquals( "result", i.objectTypes( new Integer(1) ) ); mock.verify(); } } |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv11992/src/core/test/mockobjects Added Files: TestExpectationValue.java TestAssertMo.java TestExpectationMap.java TestExpectationList.java TestExpectationSet.java TestVerifier.java TestMapEntry.java TestExpectationCounter.java TestReturnObjectList.java TestNull.java TestExpectationCollection.java AllTests.java TestExpectationSegment.java TestExpectationDoubleValue.java Log Message: moved test classes to a new package --- NEW FILE: TestExpectationValue.java --- package test.mockobjects; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; /** * JUnit test case for TestExpectationValue */ public class TestExpectationValue extends TestCaseMo { private static final Class THIS = TestExpectationValue.class; private ExpectationValue myExpectation = new ExpectationValue("ExpectationValue for testing"); public TestExpectationValue(String name) { super(name); } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testBooleanFail() { myExpectation.setExpected(true); boolean testPasses = false; try { myExpectation.setActual(false); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on boolean", testPasses); } public void testBooleanPass() { myExpectation.setExpected(true); myExpectation.setActual(true); myExpectation.verify(); } public void testExpectNothing() { myExpectation.setExpectNothing(); assertTrue("Should have an expectation", myExpectation.hasExpectations()); } public void testExpectNothingFail() { myExpectation.setExpectNothing(); boolean testPasses = false; try { myExpectation.setActual("another object"); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on object", testPasses); } public void testFailOnVerify() { myExpectation.setExpected("string object"); myExpectation.setFailOnVerify(); myExpectation.setActual("another object"); assertVerifyFails(myExpectation); } public void testFlushActual() { myExpectation.setActual(10); myExpectation.setExpectNothing(); myExpectation.verify(); } public void testHasNoExpectations() { myExpectation.setActual("a value"); assertTrue("Has no expectations", !myExpectation.hasExpectations()); } public void testIntFail() { myExpectation.setExpected(100); boolean testPasses = false; try { myExpectation.setActual(150); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on int", testPasses); } public void testIntPass() { myExpectation.setExpected(100); myExpectation.setActual(100); myExpectation.verify(); } public void testLongFail() { myExpectation.setExpected(100L); boolean testPasses = false; try { myExpectation.setActual(150L); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on long", testPasses); } public void testLongPass() { myExpectation.setExpected(100L); myExpectation.setActual(100L); myExpectation.verify(); } public void testDoubleFail() { myExpectation.setExpected(100.0); boolean testPasses = false; try { myExpectation.setActual(150.0); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on double", testPasses); } public void testDoublePass() { myExpectation.setExpected(100.0); myExpectation.setActual(100.0); myExpectation.verify(); } public void testNullFail() { myExpectation.setExpected(null); boolean testPasses = false; try { myExpectation.setActual("another object"); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on object", testPasses); } public void testNullPass() { myExpectation.setExpected(null); myExpectation.setActual(null); myExpectation.verify(); } public void testObject() { myExpectation.setExpected("string object"); myExpectation.setActual("string object"); myExpectation.verify(); } public void testObjectFail() { myExpectation.setExpected("string object"); boolean testPasses = false; try { myExpectation.setActual("another object"); } catch (AssertionFailedError ex) { testPasses = true; } assertTrue("Should fail fast on object", testPasses); } } --- NEW FILE: TestAssertMo.java --- package test.mockobjects; import java.util.Vector; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; public class TestAssertMo extends TestCaseMo { private static final Class THIS = TestAssertMo.class; public TestAssertMo(String name) { super(name); } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testAssertExcludes() { AssertMo.assertExcludes( "Should not include substring", "dog", "The quick brown fox"); } public void testAssertExcludesFails() { Throwable result = null; try { AssertMo.assertExcludes( "Should fail on exclude", "fox", "The quick brown fox"); } catch (AssertionFailedError ex) { result = ex; } assertTrue("Should get an exception", result != null); } public void testAssertIncludes() { AssertMo.assertIncludes( "Should include a substring", "fox", "The quick brown fox"); } public void testAssertIncludesFails() { Throwable result = null; try { AssertMo.assertIncludes( "Should fail if no include", "dog", "The quick brown fox"); } catch (AssertionFailedError ex) { result = ex; } assertTrue("Should get an exception", result != null); } public void testAssertStartsWith() { AssertMo.assertStartsWith( "Should start with fox", "fox", "fox quick brown"); } public void testAssertStartsWithFails() { Throwable result = null; try { AssertMo.assertStartsWith( "Should fail if it doesn't start with fox", "fox", "The quick brown fox"); } catch (AssertionFailedError ex) { result = ex; } assertTrue("Should get an exception", result != null); } public void testDifferentArrays() { Object[] anExpectedArray = new Object[] { "one", new Integer(2)}; Object[] anActualArray = new Object[] { "two", new Integer(2)}; boolean threwException = false; try { AssertMo.assertEquals( "Should be expected value", anExpectedArray, anActualArray); } catch (AssertionFailedError ignoredException) { threwException = true; } assertTrue("should have thrown assertion failure", threwException); } public void testDifferentLengthArrays() { Object[] anExpectedArray = new Object[] { "one", new Integer(2)}; Object[] anActualArray = new Object[] { "one" }; boolean threwException = false; try { AssertMo.assertEquals( "Should be expected value", anExpectedArray, anActualArray); } catch (AssertionFailedError ignoredException) { threwException = true; } assertTrue("should have thrown assertion failure", threwException); } public void testDifferentObjectArrays() { Object[] anExpectedArray = new Object[] { "one", new Integer(2)}; Object[] anActualArray = new Object[] { new Integer(2), new Vector()}; boolean threwException = false; try { AssertMo.assertEquals( "Should be expected value", anExpectedArray, anActualArray); } catch (AssertionFailedError ignoredException) { threwException = true; } assertTrue("should have thrown assertion failure", threwException); } public void testEqualArrays() { Object[] anExpectedArray = new Object[] { "one", new Integer(2)}; Object[] anActualArray = new Object[] { "one", new Integer(2)}; AssertMo.assertEquals( "Should be expected value", anExpectedArray, anActualArray); } public void testEqualEmptyArrays() { Object[] anExpectedArray = new Object[0]; Object[] anActualArray = new Object[0]; AssertMo.assertEquals( "Should be expected value", anExpectedArray, anActualArray); } } --- NEW FILE: TestExpectationMap.java --- package test.mockobjects; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; /** * JUnit test case for TestExpectationMap */ public class TestExpectationMap extends TestCaseMo { private static final Class THIS = TestExpectationMap.class; public TestExpectationMap(String name) { super(name); } public static void main(String[] args) { new junit.awtui.TestRunner().run(THIS); } public void testExpectMissingEntry() { ExpectationMap map = new ExpectationMap("map"); map.addExpectedMissing("key"); assertEquals("one entry", null, map.get("key")); map.verify(); } public void testExpectNullEntry() { ExpectationMap map = new ExpectationMap("map"); try { map.addExpected("key", null); assertEquals("one entry", null, map.get("key")); map.verify(); } catch (NullPointerException ex) { AssertMo.assertStartsWith( "Should be JDK 1.1.7A", "1.1", System.getProperty("java.version")); } } public void testExpectOneEntry() { ExpectationMap map = new ExpectationMap("map"); map.addExpected("key", "value"); assertEquals("one entry", "value", map.get("key")); map.verify(); } public void testExpectTwoEntries() { ExpectationMap map = new ExpectationMap("map"); map.addExpected("key", "value"); map.addExpected("key1", "value1"); assertEquals("two entries", "value", map.get("key")); assertEquals("two entries", "value1", map.get("key1")); map.verify(); } public void testFailOneEntry() { try { ExpectationMap map = new ExpectationMap("map"); map.setExpectNothing(); map.get("key"); } catch (AssertionFailedError ex) { return; } fail("should fail one entry"); } public void testFailOnVerify() { ExpectationMap map = new ExpectationMap("map"); map.setExpectNothing(); map.setFailOnVerify(); map.get("key"); try { map.verify(); } catch (AssertionFailedError ex) { return; } fail("should fail one entry"); } public void testOverwriteEntry() { ExpectationMap map = new ExpectationMap("map"); map.addExpected("key", "value"); map.addExpected("key", "value1"); assertEquals("overwrite entry", "value1", map.get("key")); map.verify(); } } --- NEW FILE: TestExpectationList.java --- package test.mockobjects; import java.util.*; import junit.framework.*; import com.mockobjects.*; import test.mockobjects.TestExpectationCollection; public class TestExpectationList extends TestExpectationCollection { private static final Class THIS = TestExpectationList.class; public TestExpectationList(String name) { super(name); myExpectation = new ExpectationList(name); } public void lookAtTheSuperclassForTests() { } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testSorted() { myExpectation.addExpected("A"); myExpectation.addExpected("B"); myExpectation.addActual("A"); myExpectation.addActual("B"); myExpectation.verify(); } } --- NEW FILE: TestExpectationSet.java --- package test.mockobjects; import java.util.*; import junit.framework.*; import com.mockobjects.*; import test.mockobjects.TestExpectationCollection; public class TestExpectationSet extends TestExpectationCollection { private static final Class THIS = TestExpectationSet.class; public TestExpectationSet(String name) { super(name); myExpectation = new ExpectationSet(name); } public void lookAtTheSuperclassForTests() { } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testMultiUnsorted() { myExpectation.addExpectedMany(new String[] { "A", "B" }); myExpectation.addActualMany(new String[] { "A", "B" }); myExpectation.verify(); } public void testMultiUnsortedSet() { myExpectation.addExpectedMany(new String[] { "A", "B" }); myExpectation.addActualMany(new String[] { "A", "B", "A", "B" }); myExpectation.verify(); } public void testUnsorted() { myExpectation.addExpected("A"); myExpectation.addExpected("B"); myExpectation.addActual("B"); myExpectation.addActual("A"); myExpectation.verify(); } public void testUnsortedSet() { myExpectation.addExpected("A"); myExpectation.addExpected("B"); myExpectation.addActual("A"); myExpectation.addActual("B"); myExpectation.addActual("A"); myExpectation.addActual("B"); myExpectation.verify(); } } --- NEW FILE: TestVerifier.java --- package test.mockobjects; import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; import com.mockobjects.util.TestCaseMo; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestSuite; public class TestVerifier extends TestCaseMo { private static final Class THIS = TestVerifier.class; class OneVerifiable extends MockObject { private ExpectationValue myValue = new ExpectationValue("should fail"); private int unusedField; public OneVerifiable() { myValue.setFailOnVerify(); myValue.setExpected("good"); } public void setValue(String aValue) { myValue.setActual(aValue); } } class InheritVerifiable extends OneVerifiable { } class LoopingVerifiable extends MockObject { LoopingVerifiable myRef = this; boolean inVerify = false; LoopingVerifiable() { super(); } public void setRef(LoopingVerifiable aRef) { myRef = aRef; } public void verify() { assertTrue("Looping verification detected", !inVerify); inVerify = true; super.verify(); inVerify = false; } } public TestVerifier(String name) { super(name); } public static void main(String[] args) { start(new String[]{THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testInheritVerifiableFails() { InheritVerifiable inheritVerifiable = new InheritVerifiable(); inheritVerifiable.setValue("bad"); boolean hasThrownException = false; try { inheritVerifiable.verify(); } catch (AssertionFailedError ex) { hasThrownException = true; } assertTrue("Should have thrown exception", hasThrownException); } public void testInheritVerifiablePasses() { InheritVerifiable inheritVerifiable = new InheritVerifiable(); inheritVerifiable.setValue("good"); inheritVerifiable.verify(); } public void testNoVerifiables() { class NoVerifiables extends MockObject { } new NoVerifiables().verify(); } public void testOneVerifiableFails() { OneVerifiable oneVerifiable = new OneVerifiable(); oneVerifiable.setValue("bad"); boolean hasThrownException = false; try { oneVerifiable.verify(); } catch (AssertionFailedError ex) { hasThrownException = true; } assertTrue("Should have thrown exception", hasThrownException); } public void testOneVerifiablePasses() { OneVerifiable oneVerifiable = new OneVerifiable(); oneVerifiable.setValue("good"); oneVerifiable.verify(); } public void testNoLoopVerifySingleLevel() { new LoopingVerifiable().verify(); } public void testNoLoopVerifyMultiLevel() { LoopingVerifiable a = new LoopingVerifiable(); LoopingVerifiable b = new LoopingVerifiable(); a.setRef(b); b.setRef(a); a.verify(); } } --- NEW FILE: TestMapEntry.java --- package test.mockobjects; import com.mockobjects.MapEntry; import com.mockobjects.util.TestCaseMo; import junit.framework.Test; import junit.framework.TestSuite; /** * JUnit test case for TestMapEntry */ public class TestMapEntry extends TestCaseMo { public TestMapEntry(String name) { super(name); } public static void main(String[] args) { start(new String[]{TestMapEntry.class.getName()}); } public static Test suite() { return new TestSuite(TestMapEntry.class); } public void testEquals() { assertEquals( "Should be expected value", new MapEntry("A", "2"), new MapEntry("A", "2")); assertTrue( "Should not be equal", !new MapEntry("A", "2").equals(new MapEntry("A", "1"))); assertTrue( "Should not be equal", !new MapEntry("A", "2").equals(new MapEntry("B", "2"))); assertEquals( "Should be equal with null value", new MapEntry("A", null), new MapEntry("A", null)); assertEquals( "Should be equal with null key", new MapEntry(null, "A"), new MapEntry(null, "A")); assertEquals( "Should be equal byte arrays", new MapEntry("A", "A".getBytes()), new MapEntry("A", "A".getBytes())); assertTrue( "Should not be equal byte arrays", !new MapEntry("A", "AB".getBytes()).equals(new MapEntry("A", "A".getBytes()))); assertTrue( "Should not be equal byte arrays", !new MapEntry("A", "A".getBytes()).equals(new MapEntry("A", "AB".getBytes()))); assertTrue( "Should not be equal byte arrays", !new MapEntry("A", null).equals(new MapEntry("A", "AB".getBytes()))); } public void testHashCode() { assertEquals( "Should be equal hashcodes", new MapEntry("A", "A".getBytes()).hashCode(), new MapEntry("A", "A".getBytes()).hashCode()); } } --- NEW FILE: TestExpectationCounter.java --- package test.mockobjects; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; /** * JUnit test case for TestExpectationCounter */ public class TestExpectationCounter extends TestCaseMo { private static final Class THIS = TestExpectationCounter.class; public TestExpectationCounter(String name) { super(name); } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testExpectNothing() { ExpectationCounter e = new ExpectationCounter(""); e.setExpectNothing(); assertTrue("Has expectation", e.hasExpectations()); e.verify(); } public void testExpectNothingFailure() { ExpectationCounter e = new ExpectationCounter(""); e.setExpectNothing(); assertTrue("Has expectation", e.hasExpectations()); try { e.inc(); } catch (AssertionFailedError ex) { return; } fail("Should have failed immediately"); } public void testFailImmediately() { ExpectationCounter aCounter = new ExpectationCounter("a test counter"); aCounter.setExpected(1); aCounter.inc(); try { aCounter.inc(); } catch (AssertionFailedError ex) { return; } fail("Should have failed immediately"); } public void testFailOnVerify() { ExpectationCounter aCounter = new ExpectationCounter("a test counter"); aCounter.setExpected(1); aCounter.setFailOnVerify(); aCounter.inc(); aCounter.inc(); assertVerifyFails(aCounter); } public void testFailure() { ExpectationCounter e = new ExpectationCounter(""); e.setExpected(1); assertVerifyFails(e); } public void testFlushActual() { ExpectationCounter e = new ExpectationCounter(""); e.inc(); e.setExpected(1); e.inc(); e.verify(); } public void testHasNoExpectations() { ExpectationCounter aCounter = new ExpectationCounter("a test counter"); aCounter.inc(); assertTrue("Has no expectations", !aCounter.hasExpectations()); } public void testSuccess() { ExpectationCounter e = new ExpectationCounter(""); e.setExpected(1); e.inc(); e.verify(); } } --- NEW FILE: TestReturnObjectList.java --- package test.mockobjects; import java.util.*; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; public class TestReturnObjectList extends TestCaseMo { private ReturnObjectList list = new ReturnObjectList("test"); public TestReturnObjectList(String name) { super(name); } public static void main(String[] args) { start(new String[] { TestReturnObjectList.class.getName()}); } public void testLeftoverObjectFails() { list.addObjectToReturn("one"); assertVerifyFails(list); } public void testEmptyList() { list.verify(); } public void testReturnSucceeds() { list.addObjectToReturn("one"); list.addObjectToReturn("two"); assertEquals("Should be first result", "one", list.nextReturnObject()); assertEquals("Should be second result", "two", list.nextReturnObject()); list.verify(); } public void testTooManyReturns() { try{ list.nextReturnObject(); fail("Error should have been raised"); } catch(AssertionFailedError expected){ } } } --- NEW FILE: TestNull.java --- package test.mockobjects; import java.util.*; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; /** * JUnit test case for TestMapEntry */ public class TestNull extends TestCaseMo { public TestNull(String name) { super(name); } public static void main(String[] args) { start(new String[] { TestNull.class.getName()}); } public static Test suite() { return new TestSuite(TestNull.class); } public void testEquals() { assertEquals("Should be same value", new Null(), new Null()); assertEquals("Should be same hashCode", new Null().hashCode(), new Null().hashCode()); assertEquals("Should be same value", new Null("one"), new Null("two")); assertEquals("Should be same hashCode", new Null("one").hashCode(), new Null("two").hashCode()); // Compare with other objects to assert that they are not equal assertEquals("Not equal to something else", false, new Null("one").equals("one")); assertEquals("Not equal to something else", false, new Null().equals(new Integer(2))); } public void testDescription() { assertEquals("Description", "what it is", new Null("what it is").toString()); } } --- NEW FILE: TestExpectationCollection.java --- package test.mockobjects; import java.util.*; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; public abstract class TestExpectationCollection extends TestCaseMo { ExpectationCollection myExpectation; public TestExpectationCollection(String name) { super(name); } public void testEmpty() { myExpectation.verify(); } public void testFailImmediately() { myExpectation.addExpected("A"); myExpectation.addExpected("B"); myExpectation.addActual("A"); try { myExpectation.addActual("C"); } catch (AssertionFailedError ex) { return; } fail("Should have failed immediately"); } public void testFailImmediatelyAddingTooMany() { myExpectation.addExpected("A"); myExpectation.addActual("A"); try { myExpectation.addActual("C"); } catch (AssertionFailedError ex) { return; } fail("Should have failed immediately"); } public void testFailOnSizes() { myExpectation.addExpected("A"); myExpectation.addExpected("B"); myExpectation.addActual("A"); myExpectation.addActual("B"); try { myExpectation.addActual("C"); } catch (AssertionFailedError ex) { return; } fail("Should have failed immediately"); } public void testFailOnVerify() { myExpectation.setFailOnVerify(); myExpectation.addExpectedMany(new String[] { "A", "B" }); myExpectation.addActualMany(new String[] { "C", "A" }); assertVerifyFails(myExpectation); } public void testFlushActual() { myExpectation.addActual("a value"); myExpectation.setExpectNothing(); myExpectation.verify(); } public void testHasExpectations() { assertTrue( "Should not have any expectations", !myExpectation.hasExpectations()); myExpectation.addExpected("item"); assertTrue("Should have an expectation", myExpectation.hasExpectations()); } public void testHasExpectationsForAddingManyArray() { assertTrue( "Should not have any expectations", !myExpectation.hasExpectations()); myExpectation.addExpectedMany(new Object[0]); assertTrue("Should have an expectation", myExpectation.hasExpectations()); } public void testHasExpectationsForAddingManyVector() { assertTrue( "Should not have any expectations", !myExpectation.hasExpectations()); myExpectation.addExpectedMany(new Vector().elements()); assertTrue("Should have an expectation", myExpectation.hasExpectations()); } public void testHasNoExpectations() { myExpectation.addActual("a value"); assertTrue("Has no expectations", !myExpectation.hasExpectations()); } public void testManyFromEnumeration() { Vector expectedItems = new Vector(); expectedItems.addElement("A"); expectedItems.addElement("B"); Vector actualItems = (Vector) expectedItems.clone(); myExpectation.addExpectedMany(expectedItems.elements()); myExpectation.addActualMany(actualItems.elements()); myExpectation.verify(); } public void testManyFromIterator() { Vector expectedItems = new Vector(); expectedItems.addElement("A"); expectedItems.addElement("B"); Vector actualItems = (Vector) expectedItems.clone(); myExpectation.addExpectedMany(expectedItems.iterator()); myExpectation.addActualMany(actualItems.iterator()); myExpectation.verify(); } public void testMultiFailureFromEnumeration() { Vector expectedItems = new Vector(); expectedItems.addElement("A"); expectedItems.addElement("B"); Vector actualItems = new Vector(); actualItems.addElement("A"); actualItems.addElement("C"); myExpectation.addExpectedMany(expectedItems.elements()); myExpectation.setFailOnVerify(); myExpectation.addActualMany(actualItems.elements()); assertVerifyFails(myExpectation); } public void testMultiFailureFromIterator() { Vector expectedItems = new Vector(); expectedItems.addElement("A"); expectedItems.addElement("B"); Vector actualItems = new Vector(); actualItems.addElement("A"); actualItems.addElement("C"); myExpectation.addExpectedMany(expectedItems.iterator()); myExpectation.setFailOnVerify(); myExpectation.addActualMany(actualItems.iterator()); assertVerifyFails(myExpectation); } public void testMultiFailureSizes() { myExpectation.addExpectedMany(new String[] { "A", "B" }); myExpectation.setFailOnVerify(); myExpectation.addActualMany(new String[] { "A", "B", "C" }); assertVerifyFails(myExpectation); } } --- NEW FILE: AllTests.java --- package test.mockobjects; import com.mockobjects.util.SuiteBuilder; import com.mockobjects.util.TestCaseMo; import junit.framework.Test; import junit.framework.TestSuite; /** * JUnit test case for AllTests */ public class AllTests extends TestCaseMo { private static final Class THIS = AllTests.class; public AllTests(String name) { super(name); } public static void addTestAssertMo(TestSuite suite) { suite.addTest(TestAssertMo.suite()); } public static void addTestExpectationCounter(TestSuite suite) { suite.addTest(TestExpectationCounter.suite()); } public static void addTestExpectationList(TestSuite suite) { suite.addTest(TestExpectationList.suite()); } public static void addTestExpectationMap(TestSuite suite) { suite.addTestSuite(TestExpectationMap.class); } public static void addTestExpectationSegment(TestSuite suite) { suite.addTest(TestExpectationSegment.suite()); } public static void addTestExpectationSet(TestSuite suite) { suite.addTest(TestExpectationSet.suite()); } public static void addTestExpectationValue(TestSuite suite) { suite.addTest(TestExpectationValue.suite()); } public static void addTestExpectationDoubleValue(TestSuite suite) { suite.addTest(TestExpectationDoubleValue.suite()); } public static void addTestMapEntry(TestSuite suite) { suite.addTest(TestMapEntry.suite()); } public static void addTestNull(TestSuite suite) { suite.addTestSuite(TestNull.class); } public static void addTestVerifier(TestSuite suite) { suite.addTest(TestVerifier.suite()); } public static void addTestReturnObjectList(TestSuite suite) { suite.addTestSuite(TestReturnObjectList.class); } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return SuiteBuilder.buildTest(THIS); } } --- NEW FILE: TestExpectationSegment.java --- package test.mockobjects; import java.io.*; import java.util.*; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; public class TestExpectationSegment extends TestCaseMo { private static final Class THIS = TestExpectationSegment.class; private ExpectationSegment myExpectation; public TestExpectationSegment(String name) { super(name); } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public void setUp() { myExpectation = new ExpectationSegment("Expectation segment"); } public static Test suite() { return new TestSuite(THIS); } public void testExpectNothing() { myExpectation.setExpectNothing(); assertTrue("Should have an expectation", myExpectation.hasExpectations()); } public void testExpectNothingFail() { myExpectation.setExpectNothing(); boolean hasThrownException = false; try { myExpectation.setActual("some string"); } catch (AssertionFailedError ex) { hasThrownException = true; } assertTrue("Should fail fast", hasThrownException); } public void testFailOnVerify() { myExpectation.setExpected("a segment"); myExpectation.setFailOnVerify(); myExpectation.setActual("string without stuff"); assertVerifyFails(myExpectation); } public void testFailsImmediately() { boolean hasThrownException = false; myExpectation.setExpected("inner"); try { myExpectation.setActual("String not containing segment"); } catch (AssertionFailedError expected) { hasThrownException = true; } assertTrue("Should have thrown exception", hasThrownException); } public void testFlushActual() { myExpectation.setActual("a string"); myExpectation.setExpectNothing(); myExpectation.verify(); } public void testHasNoExpectations() { myExpectation.setActual("a string"); assertTrue("Has no expectations", !myExpectation.hasExpectations()); } public void testPasses() { myExpectation.setExpected("inner"); myExpectation.setActual("String containing inner segment"); myExpectation.verify(); } } --- NEW FILE: TestExpectationDoubleValue.java --- package test.mockobjects; import junit.framework.*; import com.mockobjects.*; import com.mockobjects.util.*; public class TestExpectationDoubleValue extends TestCaseMo { private static final Class THIS = TestExpectationDoubleValue.class; private ExpectationDoubleValue myExpectation = new ExpectationDoubleValue("ExpectationDoubleValue for testing"); public TestExpectationDoubleValue(String name) { super(name); } public static void main(String[] args) { start(new String[] { THIS.getName()}); } public static Test suite() { return new TestSuite(THIS); } public void testExpectNothing() { myExpectation.setExpectNothing(); assertTrue("Should have an expectation", myExpectation.hasExpectations()); } public void testExpectNothingFail() { myExpectation.setExpectNothing(); try { myExpectation.setActual(100.0); fail("Should fail fast"); } catch (AssertionFailedError ex) { // expected } } public void testFailOnVerify() { myExpectation.setExpected( 0.0, 0.0 ); myExpectation.setFailOnVerify(); myExpectation.setActual(1.0); assertVerifyFails(myExpectation); } public void testFlushActual() { myExpectation.setActual(10); myExpectation.setExpectNothing(); myExpectation.verify(); } public void testHasNoExpectations() { myExpectation.setActual(0.0); assertTrue( "Has no expectations", !myExpectation.hasExpectations()); } public void testFailOutsideError() { myExpectation.setExpected( 100.0, 1.0 ); try { myExpectation.setActual(102.0); fail("Should fail fast on double"); } catch (AssertionFailedError ex) { //expected } } public void testPassOnError() { myExpectation.setExpected( 100.0, 1.0 ); myExpectation.setActual(101.0); myExpectation.verify(); } public void testPassWithinError() { myExpectation.setExpected( 100.0, 1.0 ); myExpectation.setActual(100); myExpectation.verify(); } } |
From: Steve F. <sm...@us...> - 2002-10-21 22:51:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv11177/src/core/test/mockobjects/dynamic Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects/dynamic added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:51:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test In directory usw-pr-cvs1:/tmp/cvs-serv11177/src/core/test Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/core/test added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:51:46
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv11177/src/core/test/mockobjects Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/core/test/mockobjects added to the repository |
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv10819/src/core/com/mockobjects/dynamic Added Files: IsGreaterThan.java IsLessThan.java Mock.java ExpectedCall.java IsCloseTo.java P.java Or.java ExpectedReturn.java IsEventFrom.java IsSame.java IsNull.java And.java IsNot.java Predicate.java IsAnything.java ExpectedThrow.java IsEqual.java IsInstanceOf.java Log Message: added dynamic mocks library --- NEW FILE: IsGreaterThan.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Is the argument greater than another {@link java.lang.Comparable} value? */ public class IsGreaterThan implements Predicate { private Comparable _object; /** Creates a new instance of IsGreaterThan */ public IsGreaterThan( Comparable o ) { _object = o; } public boolean eval( Object arg ) { return _object.compareTo(arg) < 0; } public String toString() { return "a value greater than <" + _object.toString() + ">"; } } --- NEW FILE: IsLessThan.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Is the argument less than another {@link java.lang.Comparable} value? */ public class IsLessThan implements Predicate { private Comparable _object; /** Creates a new instance of IsLessThan */ public IsLessThan(Comparable o) { _object = o; } public boolean eval( Object arg ) { return _object.compareTo(arg) > 0; } public String toString() { return "a value less than <" + _object.toString() + ">"; } } --- NEW FILE: Mock.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:06 PM */ package com.mockobjects.dynamic; import junit.framework.AssertionFailedError; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.HashMap; import java.util.Set; import com.mockobjects.dynamic.ExpectedCall; import com.mockobjects.dynamic.ExpectedReturn; import com.mockobjects.dynamic.ExpectedThrow; import com.mockobjects.Verifiable; /** A convenient class for creating simple * <a href="http://www.mockobjects.com">mock objects</a>. */ public class Mock extends junit.framework.Assert implements InvocationHandler, Verifiable { /** A convenient constant for defining expectations for methods that * have no methods. */ public static final Predicate[] NO_ARGS = new Predicate[0]; private String _name; private Map _expectations = new HashMap(); private Set _not_called_expectations = new HashSet(); private Map _order_constraints = new HashMap(); private Set _called_methods = new HashSet(); private boolean _strict = false; private Map _default_results = new HashMap(); /** Creates a named Mock object, The name will be included in the messages * of exceptions thrown to indicate violated expectations. */ public Mock( String name ) { _name = name; setupDefaultResult( byte.class, new Byte((byte)0) ); setupDefaultResult( short.class, new Short((short)0) ); setupDefaultResult( int.class, new Integer(0) ); setupDefaultResult( long.class, new Long(0L) ); setupDefaultResult( float.class, new Float(0.0f) ); setupDefaultResult( double.class, new Double(0.0d) ); setupDefaultResult( boolean.class, Boolean.FALSE ); setupDefaultResult( char.class, new Character('\0') ); setupDefaultResult( String.class, "" ); } /** Creates a Mock object and automatically assigns a name to it. The assigned * name will include the name of the concrete class and a unique identifier of * this instance, but will not be particularly user friendly when included in * error messages. Therefore, it is recommended that you explictly name mock * objects if you use more than one in the same test case. */ public Mock() { this(null); _name = super.toString(); } /** Returns the Mock's name. */ public String toString() { return _name; } /** Is the mock in strict mode? In strict mode the mock will throw * {@link junit.framework.AssertionFailedError} exceptions when * unexpected method calls are made. Otherwise, the mock ignore * the call or return default arguments. */ public boolean isStrict() { return _strict; } public void setStrict( boolean strict ) { _strict = strict; } /** Mock the behaviour of a method without requiring that the method * actually be called. Note: the ExpectedCall may check the arguments * of the call but should usually not do so. * * @param call * The call to be mocked. */ public void setup( ExpectedCall call ) { _expectations.put( call.getMethodName(), call ); _not_called_expectations.remove( call.getMethodName() ); _called_methods.add( call.getMethodName() ); } /** Set up calls to <var>method</var> to return <var>result</var>, * but do not define any expectations upon arguments to those calls. * Arguments of calls to <var>method</var> will be ignored. * * @param method_name * The name of the method that will be called. * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void setupResult( String method_name, Object result ) { setup( new ExpectedReturn( method_name, null, result ) ); } /** Set up calls to <var>method</var> to throw <var>exception</var>, * but do not define any expectations upon arguments to those calls. * Arguments of calls to <var>method</var> will be ignored. * * @param method_name * The name of the method that will be called. * @param exception * The exception or error that will be thrown as a result of this call. */ public void setupThrow( String method_name, Throwable exception ) { setup( new ExpectedThrow( method_name, null, exception ) ); } /** Set up the value returned by methods that have the given result * type, if no result or exception has been explicitly defined for * the called method by {@link #setupResult}, {@link #setupThrow}, * {@link #expectReturn} or {@link #expectThrow}. * * @param result_type * The result type of methods to be mocked. * @param result_value * The default value returned by mocked methods that return values * of type <var>result_type</var>. */ public void setupDefaultResult( Class result_type, Object result_value ) { _default_results.put( result_type, result_value ); } /** Expect a method call and mock the behaviour of that call. * * @param call * An object describing the expected call and mocking its behaviour. */ public void expect( ExpectedCall call ) { _expectations.put( call.getMethodName(), call ); _not_called_expectations.remove( call.getMethodName() ); _called_methods.remove( call.getMethodName() ); } /** Expect a method call and return a result when it is called. * * @param method * The name of the method that will be called. * @param args * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void expectReturn( String method, Predicate[] args, Object result ) { expect( new ExpectedReturn( method, args, result ) ); } /** Expect a method call and return a result when it is called. * * @param method * The name of the method that will be called. * @param arg * An single object that will be compared with predicate same() * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void expectReturn( String method, Object arg, Object result ) { expect( new ExpectedReturn( method, P.arg(P.same(arg)), result ) ); } /** Expect a method call with no parameters and return a result when it is called. * * @param method * The name of the method that will be called. * @param result * The result that will be returned from this call. Primitive types * must be wrapped in the equivalent Java object, and will be unwrapped * before being returned to the caller of the method. */ public void expectReturn( String method, Object result ) { expect( new ExpectedReturn( method, null, result ) ); } /** Expect a call to a method with a void return type. * * @param method * The name of the method that will be called. * @param args * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. */ public void expectVoid( String method, Predicate[] args ) { expect( new ExpectedReturn( method, args, null ) ); } /** Expect a call to a method with a void return type. * * @param method * The name of the method that will be called. * @param arg * An single object that will be compared with predicate same() */ public void expectVoid(String method, Object arg) { expect(new ExpectedReturn(method, P.arg(P.same(arg)), null)); } /** Expect a call to a method with a void return type and no parameters * * @param method * The name of the method that will be called. */ public void expectVoid(String method) { expect(new ExpectedReturn(method, null, null)); } /** Expect a method call and throw an exception or error when it is called. * * @param method * The name of the method that will be called. * @param args * An array of {@link com.mockobjects.dynamic.Predicate}s that specify the * epxected arguments of the method call. The length of the array defines * the expected arity of the method call. * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectThrow( String method, Predicate[] args, Throwable exception ) { expect( new ExpectedThrow( method, args, exception ) ); } /** Expect a method call and throw an exception or error when it is called. * * @param method * The name of the method that will be called. * @param arg * An single object that will be compared with predicate same() * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectThrow( String method, Object arg, Throwable exception ) { expect( new ExpectedThrow( method, P.arg(P.same(arg)), exception ) ); } /** Expect a method call with no parameters and throw an exception or error when it is called. * * @param method * The name of the method that will be called. * @param exception * The exception or error that will be thrown as a result of this call. */ public void expectThrow( String method, Throwable exception ) { expect( new ExpectedThrow( method, null, exception ) ); } /** Expect a method not to be called. * An {@link junit.framework.AssertionFailedError} will be thrown if * the method is called. * * @param method * The name of the method that will not be called. */ public void expectNotCalled( String method ) { _not_called_expectations.add(method); } /** Define an order between two calls. The method named * <var>subsequent_method</var> <em>must</em> be called after * the method namd <var>preceding_method</var>, otherwise an * {@link junit.framework.AssertionFailedError} will be thrown. */ public void order( String preceding_method, String subsequent_method ) { Set preceding_calls; if( _order_constraints.containsKey(subsequent_method) ) { preceding_calls = (Set)_order_constraints.get(subsequent_method); } else { preceding_calls = new HashSet(); _order_constraints.put( subsequent_method, preceding_calls ); } preceding_calls.add( preceding_method ); } /** Called by the {@link java.lang.reflect.Proxy} to mock the behaviour of an * invoked method and check expectations. */ public Object invoke( Object obj, Method method, Object[] args ) throws Throwable { _called_methods.add( method.getName() ); try { return getClass().getMethod( method.getName(), method.getParameterTypes() ).invoke( this, args ); } catch( NoSuchMethodException ex ) { return mockCall( method, args ); } } protected Object mockCall( Method method, Object[] args ) throws Throwable { String method_name = method.getName(); assertCanBeCalled( method_name ); if( _expectations.containsKey( method_name ) ) { ExpectedCall expected = (ExpectedCall)_expectations.get(method_name); checkCallOrder( method_name ); if( expected.isTestingArguments() ) { checkArguments( expected, args ); } return expected.eval( args ); } else if( _strict ) { throw new AssertionFailedError( _name + ": unexpected call to " + method_name ); } else { return defaultResult( method.getReturnType() ); } } private void checkCallOrder( String method_name ) { if( _order_constraints.containsKey(method_name) ) { assertMethodsHaveBeenCalled( (Set)_order_constraints.get(method_name) ); } } private void checkArguments( ExpectedCall expected, Object[] args ) { int arg_count = (args == null) ? 0 : args.length; assertEquals( _name + ": wrong number of arguments to " + expected.getMethodName() + " method", expected.getArgumentCount(), arg_count ); for( int i = 0; i < arg_count; i++ ) { Object arg = args[i]; if( !expected.testArgument( i, arg ) ) { fail( _name + ": unexpected argument " + (i+1) + " to " + expected.getMethodName() + " method" + ", expected " + expected.describeArgument(i) + ", was " + arg ); } } } private Object defaultResult( Class return_type ) { if( _default_results.containsKey(return_type) ) { return _default_results.get(return_type); } else { return null; } } /** Fails if not all the expected calls have been made to this mock object. * * @throws junit.framework.AssertionFailedError * Not all expected calls were made to this mock object. */ public void verify() { assertAllExpectedMethodsCalled(); } private void assertAllExpectedMethodsCalled() { assertMethodsHaveBeenCalled( _expectations.keySet() ); } private void assertMethodsHaveBeenCalled( Set method_names ) { Iterator i = method_names.iterator(); while( i.hasNext() ) { assertHasBeenCalled( (String)i.next() ); } } private void assertCanBeCalled( String method_name ) { if( _not_called_expectations.contains(method_name) ) { fail(_name + ": unexpected call to method " + method_name ); } } private void assertHasBeenCalled( String method_name ) { if( !_called_methods.contains(method_name) ) { fail( _name + ": method " + method_name + " was not called" ); } } public Object createInterface( Class interface_class ) { return createInterface( interface_class.getClassLoader(), new Class[]{ interface_class } ); } public Object createInterface( ClassLoader loader, Class interface_class ) { return createInterface( loader, new Class[]{ interface_class } ); } public Object createInterface( ClassLoader loader, Class[] interface_classes ) { return Proxy.newProxyInstance( loader, interface_classes, this ); } } --- NEW FILE: ExpectedCall.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:09 PM */ package com.mockobjects.dynamic; /** An expected call to a method of a mock object */ public abstract class ExpectedCall extends junit.framework.Assert { /** A constant that indicates that an <code>ExpectedCall</code> accepts * any arguments, that is, that the call does not check the arguments * passed to it. */ public static final Predicate[] ANY_ARGS = null; private String _name; private Predicate[] _expected_args; /** Constructs an <code>ExpectedCall</code> that accepts any arguments. * * @param name * The name of the expected method. */ public ExpectedCall( String name ) { this( name, ANY_ARGS ); } /** Constructs an <code>ExpectedCall</code> that checks its arguments. * * @param name * The name of the expected method. * @param expected_args * Predicates that define the valid arguments of the method. */ public ExpectedCall( String name, Predicate[] expected_args ) { _name = name; _expected_args = expected_args; } public String getMethodName() { return _name; } public boolean isTestingArguments() { return _expected_args != null; } /* Pre: isTestingArguments() */ public int getArgumentCount() { return _expected_args.length; } /* Pre: isTestingArguments() */ public boolean testArgument( int n, Object arg ) { return _expected_args[n].eval(arg); } public String describeArgument( int n ) { if( _expected_args == null ) { return "anything"; } else { return _expected_args[n].toString(); } } public abstract Object eval( Object[] args ) throws Throwable; } --- NEW FILE: IsCloseTo.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Is the argument a number equal to a value within some range of acceptable * error? */ public class IsCloseTo implements Predicate { private double _error; private double _value; public IsCloseTo( double value, double error ) { _error = error; _value = value; } public boolean eval( Object arg ) { double arg_value = ((Number)arg).doubleValue(); return Math.abs( (arg_value - _value) ) <= _error; } public String toString() { return "a numeric value within " + _error + " of " + _value; } } --- NEW FILE: P.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 14, 2002, 4:02 PM */ package com.mockobjects.dynamic; import com.mockobjects.dynamic.*; /** Convenient factory functions and constants for building predicates. */ public abstract class P { public static final IsAnything IS_ANYTHING = new IsAnything(); public static final IsNull IS_NULL = new IsNull(); public static final Predicate IS_TRUE = new IsEqual(new Boolean(true)); public static final Predicate IS_FALSE = eq(new Boolean(false)); public static final Predicate IS_ZERO = eq(new Integer(0)); public static final Predicate IS_NOT_ZERO = not(IS_ZERO); public static Predicate same( Object o ) { return new IsSame(o); } public static Predicate eq( Object o ) { return new IsEqual(o); } public static Predicate eq( int n ) { return new IsEqual( new Integer(n) ); } public static Predicate eq( long l ) { return new IsEqual( new Long(l) ); } public static Predicate eq( double d ) { return new IsEqual( new Double(d) ); } public static Predicate gt( int n ) { return new IsGreaterThan( new Integer(n) ); } public static Predicate gt( long l ) { return new IsGreaterThan( new Long(l) ); } public static Predicate gt( double d ) { return new IsGreaterThan( new Double(d) ); } public static Predicate gt( char c ) { return new IsGreaterThan( new Character(c) ); } public static Predicate lt( int n ) { return new IsLessThan( new Integer(n) ); } public static Predicate lt( long l ) { return new IsLessThan( new Long(l) ); } public static Predicate lt( double d ) { return new IsLessThan( new Double(d) ); } public static Predicate lt( char c ) { return new IsLessThan( new Character(c) ); } public static Predicate not( Predicate p ) { return new IsNot(p); } public static Predicate and( Predicate p1, Predicate p2 ) { return new And(p1,p2); } public static Predicate or( Predicate p1, Predicate p2 ) { return new Or(p1,p2); } public static Predicate isA( Class c ) { return new IsInstanceOf(c); } /* Helper methods for succinctly constructing Predicate arrays */ public static Predicate[] arg(Predicate p) { return new Predicate[] {p}; } public static Predicate[] args(Predicate p1, Predicate p2) { return new Predicate[] {p1, p2}; } public static Predicate[] args(Predicate p1, Predicate p2, Predicate p3) { return new Predicate[] {p1, p2, p3}; } } --- NEW FILE: Or.java --- /* Copyright (c) 2002 B13media Ltd. All rights reserved. * * Created on February 10, 2002, 11:49 PM */ package com.mockobjects.dynamic; /** Calculates the logical disjunction of two predicates. */ public class Or implements Predicate { Predicate _p1, _p2; public Or( Predicate p1, Predicate p2 ) { _p1 = p1; _p2 = p2; } public boolean eval( Object o ) { if( _p1.eval(o) ) { return true; } else { return _p2.eval(o); } } public String toString() { return "(" + _p1.toString() + " or " + _p2.toString() + ")"; } } --- NEW FILE: ExpectedReturn.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:59 PM */ package com.mockobjects.dynamic; import com.mockobjects.dynamic.ExpectedCall; /** An expected method call that returns a result. */ class ExpectedReturn extends ExpectedCall { private Object _result; public ExpectedReturn( String name, Object result ) { this( name, ANY_ARGS, result ); } public ExpectedReturn( String name, Predicate[] expected_args, Object result ) { super( name, expected_args ); _result = result; } public Object eval( Object[] args ) throws Throwable { return _result; } } --- NEW FILE: IsEventFrom.java --- /** Created on Jun 28, 2002 by npryce * Copyright (c) B13media Ltd. */ package com.mockobjects.dynamic; import java.util.EventObject; /** Tests if the argument is an event announced by a specific object. */ public class IsEventFrom implements Predicate { private Class _event_class; private Object _source; /** Constructs an IsEventFrom predicate that returns true for any object * derived from {@link java.util.EventObject} announced by * <var>source</var>. */ public IsEventFrom( Object source ) { this( EventObject.class, source ); } /** Constructs an IsEventFrom predicate that returns true for any object * derived from <var>event_class</var> announced by * <var>source</var>. */ public IsEventFrom( Class event_class, Object source ) { _event_class = event_class; _source = source; } public boolean eval( Object o ) { if( o instanceof EventObject ) { EventObject ev = (EventObject)o; return _event_class.isInstance(o) && ev.getSource() == _source; } else { return false; } } public String toString() { return "an event of type " + _event_class.getName() + " from " + _source.toString(); } } --- NEW FILE: IsSame.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Is the argument the same object as another value? */ public class IsSame implements Predicate { private Object _object; /** Creates a new instance of IsSame * * @param o * The predicate evaluates to true only when the argument is * this object. */ public IsSame(Object o) { _object = o; } public boolean eval( Object arg ) { return arg == _object; } public String toString() { return "the same object as <" + _object.toString() + ">"; } } --- NEW FILE: IsNull.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:33 PM */ package com.mockobjects.dynamic; /** Is the argument null? */ public class IsNull implements Predicate { /** Creates a new instance of IsNull */ public IsNull() { } public boolean eval(Object o) { return o == null; } public String toString() { return "null"; } } --- NEW FILE: And.java --- /* Copyright (c) 2002 B13media Ltd. All rights reserved. * * Created on February 10, 2002, 11:49 PM */ package com.mockobjects.dynamic; /** Calculates the logical conjunction of two predicates. */ public class And implements Predicate { Predicate _p1, _p2; public And(Predicate p1, Predicate p2) { _p1 = p1; _p2 = p2; } public boolean eval( Object o ) { if( !_p1.eval(o) ) { return false; } else { return _p2.eval(o); } } public String toString() { return "(" + _p1.toString() + " and " + _p2.toString() + ")"; } } --- NEW FILE: IsNot.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Calculates the logical negation of a predicate. */ public class IsNot implements Predicate { private Predicate _predicate; public IsNot( Predicate p ) { _predicate = p; } public boolean eval( Object arg ) { return !_predicate.eval(arg); } public String toString() { return "not " + _predicate.toString(); } } --- NEW FILE: Predicate.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:21 PM */ package com.mockobjects.dynamic; /** A predicate used to define acceptable method arguments. */ public interface Predicate { /** Evaluates the predicate on argument <var>o</var>. */ boolean eval( Object o ); } --- NEW FILE: IsAnything.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:33 PM */ package com.mockobjects.dynamic; /** A predicate that always returns <code>true</code>. */ public class IsAnything implements Predicate { public IsAnything() { } public boolean eval(Object o) { return true; } public String toString() { return "any value"; } } --- NEW FILE: ExpectedThrow.java --- /* Copyright (c) 2002 B13media Ltd. All rights reserved. * * Created on February 10, 2002, 11:59 PM */ package com.mockobjects.dynamic; import com.mockobjects.dynamic.ExpectedCall; /** An expected method call that results in a thrown exception. */ class ExpectedThrow extends ExpectedCall { private Throwable _exception; public ExpectedThrow( String name, Throwable exception ) { this( name, ANY_ARGS, exception ); } public ExpectedThrow( String name, Predicate[] expected_args, Throwable exception ) { super( name, expected_args ); _exception = exception; } public Object eval( Object[] args ) throws Throwable { throw _exception; } } --- NEW FILE: IsEqual.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Is the argument equal to another value, as tested by the * {@link java.lang.Object#equals} method? */ public class IsEqual implements Predicate { private Object _object; /** Creates a new instance of IsEqual */ public IsEqual( Object o ) { _object = o; } public boolean eval( Object arg ) { return arg.equals(_object); } public String toString() { return "a value equal to <" + _object.toString() + ">"; } } --- NEW FILE: IsInstanceOf.java --- /* Copyright (c) 2002 Nat Pryce. All rights reserved. * * Created on February 10, 2002, 11:35 PM */ package com.mockobjects.dynamic; /** Tests whether the argument is an instance of a class. */ public class IsInstanceOf implements Predicate { private Class _class; /** 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 ) { _class = theclass; } public boolean eval( Object arg ) { return _class.isInstance( arg ); } public String toString() { return "an instance of <" + _class.getName() + ">"; } } |
From: Steve F. <sm...@us...> - 2002-10-21 22:51:00
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv10351/src/core/com/mockobjects/dynamic Log Message: Directory /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic added to the repository |
From: Steve F. <sm...@us...> - 2002-10-21 22:50:35
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv9814/doc/html Modified Files: index.html Log Message: added note about release 0.6 Index: index.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/index.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- index.html 20 Oct 2002 23:26:23 -0000 1.2 +++ index.html 21 Oct 2002 22:50:26 -0000 1.3 @@ -39,7 +39,16 @@ <tbody> <tr align="left" valign="top" rowspan="1" colspan="1" bgcolor="#a0ddf0"> - <td valign="top"><span class=" c11">2002/10/20</span> </td> + <td valign="top"><span class="c11">2002/10/20</span> </td> + <td valign="top"><span class="c11">Release <a + href="http://sourceforge.net/project/shownotes.php?release_id=117670">0.6</a>. + Folded in Nat Pryce's dynamic mock implementation and reorganised the test classes.</span> + </td> + </tr> + + <tr align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> + <td valign="top"><span class="c11">2002/10/20</span></td> <td valign="top"><span class="c11">0.5 Reorganised the <a href="http://sourceforge.net/project/showfiles.php?group_id=18189&release_id=116303">release</a> structure. Broke up the jar into several smaller jars: <code>core</code>, |
From: Steve F. <st...@m3...> - 2002-10-21 20:42:08
|
Is anyone still using SuiteBuilder to assemble JUnit tests? It strikes me that JUnit is much improved in this area and we could do away with it. Steve |
From: Nat P. <np...@us...> - 2002-10-21 17:29:03
|
Update of /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock In directory usw-pr-cvs1:/tmp/cvs-serv2155/source/com/b13media/mock Modified Files: Or.java P.java IsInstanceOf.java Matches.java Predicate.java And.java IsAnything.java IsNot.java IsEventFrom.java IsSame.java Log Message: Fixed erroneous javadoc comments caused by overenthusiastic use of copy-and-paste. Index: Or.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/Or.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- Or.java 22 May 2002 10:02:53 -0000 1.1.1.1 +++ Or.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -4,15 +4,13 @@ */ package com.b13media.mock; -/** +/** Calculates the logical disjunction of two predicates. */ public class Or implements Predicate { Predicate _p1, _p2; - /** Creates a new instance of Or - */ public Or( Predicate p1, Predicate p2 ) { _p1 = p1; _p2 = p2; @@ -27,6 +25,6 @@ } public String toString() { - return "(" + _p1.toString() + ") or (" + _p2.toString() + ")"; + return "(" + _p1.toString() + " or " + _p2.toString() + ")"; } } Index: P.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/P.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- P.java 20 Oct 2002 23:20:35 -0000 1.2 +++ P.java 21 Oct 2002 17:28:58 -0000 1.3 @@ -84,9 +84,9 @@ return new IsInstanceOf(c); } - /** - * Helper methods for succinctly constructing Predicate arrays + /* Helper methods for succinctly constructing Predicate arrays */ + public static Predicate[] arg(Predicate p) { return new Predicate[] {p}; } Index: IsInstanceOf.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/IsInstanceOf.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- IsInstanceOf.java 22 May 2002 10:02:49 -0000 1.1.1.1 +++ IsInstanceOf.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -5,15 +5,18 @@ package com.b13media.mock; -/** Is the argument equal to another value, as tested by the - * {@link java.lang.Object#equals} method? +/** Tests whether the argument is an instance of a class. */ public class IsInstanceOf implements Predicate { private Class _class; - /** Creates a new instance of IsEqual - */ + /** 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 ) { _class = theclass; } Index: Matches.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/Matches.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Matches.java 11 Oct 2002 14:57:36 -0000 1.1 +++ Matches.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -8,8 +8,7 @@ import java.util.regex.Pattern; -/** Is the argument equal to another value, as tested by the - * {@link java.lang.Object#equals} method? +/** Is the argument a string that matches a regular expression? */ public class Matches implements Predicate { Index: Predicate.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/Predicate.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- Predicate.java 22 May 2002 10:02:58 -0000 1.1.1.1 +++ Predicate.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -8,5 +8,7 @@ */ public interface Predicate { + /** Evaluates the predicate on argument <var>o</var>. + */ boolean eval( Object o ); } Index: And.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/And.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- And.java 22 May 2002 10:02:49 -0000 1.1.1.1 +++ And.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -4,15 +4,13 @@ */ package com.b13media.mock; -/** +/** Calculates the logical conjunction of two predicates. */ public class And implements Predicate { Predicate _p1, _p2; - /** Creates a new instance of And - */ public And(Predicate p1, Predicate p2) { _p1 = p1; _p2 = p2; @@ -27,6 +25,6 @@ } public String toString() { - return "(" + _p1.toString() + ") and (" + _p2.toString() + ")"; + return "(" + _p1.toString() + " and " + _p2.toString() + ")"; } } Index: IsAnything.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/IsAnything.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- IsAnything.java 22 May 2002 10:02:49 -0000 1.1.1.1 +++ IsAnything.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -5,12 +5,10 @@ package com.b13media.mock; -/** Is the argument null? +/** A predicate that always returns <code>true</code>. */ public class IsAnything implements Predicate { - /** Creates a new instance of IsAnything - */ public IsAnything() { } Index: IsNot.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/IsNot.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- IsNot.java 22 May 2002 10:02:53 -0000 1.1.1.1 +++ IsNot.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -5,15 +5,12 @@ package com.b13media.mock; -/** Is the argument equal to another value, as tested by the - * {@link java.lang.Object#equals} method? +/** Calculates the logical negation of a predicate. */ public class IsNot implements Predicate { private Predicate _predicate; - /** Creates a new instance of IsNot - */ public IsNot( Predicate p ) { _predicate = p; } Index: IsEventFrom.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/IsEventFrom.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- IsEventFrom.java 14 Oct 2002 18:01:18 -0000 1.2 +++ IsEventFrom.java 21 Oct 2002 17:28:58 -0000 1.3 @@ -6,16 +6,26 @@ import java.util.EventObject; +/** Tests if the argument is an event announced by a specific object. + */ public class IsEventFrom implements Predicate { private Class _event_class; private Object _source; + /** Constructs an IsEventFrom predicate that returns true for any object + * derived from {@link java.util.EventObject} announced by + * <var>source</var>. + */ public IsEventFrom( Object source ) { this( EventObject.class, source ); } + /** Constructs an IsEventFrom predicate that returns true for any object + * derived from <var>event_class</var> announced by + * <var>source</var>. + */ public IsEventFrom( Class event_class, Object source ) { _event_class = event_class; _source = source; Index: IsSame.java =================================================================== RCS file: /cvsroot/mockobjects/nat/jmock/source/com/b13media/mock/IsSame.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- IsSame.java 22 May 2002 10:02:53 -0000 1.1.1.1 +++ IsSame.java 21 Oct 2002 17:28:58 -0000 1.2 @@ -12,7 +12,11 @@ private Object _object; /** Creates a new instance of IsSame - */ + * + * @param o + * The predicate evaluates to true only when the argument is + * this object. + */ public IsSame(Object o) { _object = o; } |
From: Simon L. <sim...@uk...> - 2002-10-21 16:37:53
|
On Sunday 20 October 2002 16:45, Steve Freeman wrote: > It struck me that we're not really converging on this topic, partly > because we don't have enough time but mainly because we're not really > working against the same problems.=20 [...] > Unfortunately, other than the obvious getting a Connection from a=20 Statement issue we've highlighted before I haven't come across an other=20 real examples. I've really been talking in the abstract, and how=20 MockObjects could perhaps be used outside of the ideal use only in new=20 projects written with them in mind. > You post a (made-up) example of a case that you want to unit-test and > that you think needs a change. We'll respond and see if we can find a > meaningful way around it. If not, then you win the point. > The trouble is any example I come up with quickly (and unfortunately I=20 haven't got the time to do anything else), is probably going to be easily=20 picked apart by saying that it shouldn't be written that way. StrawMan: public class DataObject { private static Statment stmt =3D =09 Global.getConnection().createStatement(); public DataObject(String name, int flags, boolean readOnlyRecord) { ... } =09 ... public static DataObject load(String id) { try { result =3D stmt.executeQuery("SELECT * FROM table WHERE id =3D " + id); if (result.next()) { obj =3D new DataObject(result.getString(1), result.getInt(3), stmt.getConnection().isReadOnly()); } } catch (SQLException e) { throw DataObjectException(e.toString()); } return obj; } } You can test the object outside of the scope of the database, but the=20 database functionality is fully encapsulated in the Object itself. The=20 point of use of the load() method doesn't even need to know that the=20 database is being used. It also isn't storing and object for the sake of=20 testing (ie. the implementation knows that a statment is associated with=20 a particular connection, therefore doesn't need to store the Connection). With the com.mockobjects.sql package as it stands (or did last time I did=20 an update) setting up this situation will cause a StackOverflowError (if=20 verify is called on the Connection. This failure is partly due to the way the sql MockObjects have been=20 written, but its the verifier that actually causes the fatal error on=20 tests. I believe the verifier should be able to detect this situation (probably=20 warning about it) and cope in a far better way. Similar situations could=20 easily be created in user developed MockObjects, if any similar hierachy=20 is created, and informing them is IMO far better than crashing. > I figure that this will be a reasonably lightweight mechanism for > understanding each other and for pushing the dialogue along. One case > at a time... > This is probably the biggest difference, I'm not looking at a specific=20 single case, I'm thinking more generally. This is a very small point, far eclipsed by the discussions we've had. Whilst I think its important, more from a perception of MockObjects point=20 of view I don't much care if its taken on board any more. Particularly as=20 we appear to be the only two concerned about it in any form. I'd much rather be spending time presenting the rationisation I've done=20 for the sql objects in general in preparation for the PreparedStatement=20 work I was going to do - which I suspect treads on your beliefs of single=20 situation Mocks and no test cases (as it uses the same implementation of=20 ResultSet for multi and single row results, and has test cases to ensure=20 the various combinations of build methods give the same results). Simon., =2D-=20 =2D------------------------------------------------------------------------- Simon Levitt, Senior Development Engineer @ WorldPay plc, WorldPay Centre, The Science Park, Milton Rd., Cambridge, CB4 0WE, ENGLAND = =20 Sim...@uk... Ph:+44(0)1223 715151 F:+44(0)1223 715157 =2D------------------------ http://www.worldpay.com/ ----------------------- |
From: Steve F. <sm...@us...> - 2002-10-20 23:29:30
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbookWithJMock In directory usw-pr-cvs1:/tmp/cvs-serv30781/src/java/nostone/addressbookWithJMock Added Files: AddressBookServletTest.java AddressBookServlet.java Log Message: added version of address book servlet using JMock --- NEW FILE: AddressBookServletTest.java --- package nostone.addressbookWithJMock; import junit.framework.TestCase; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import com.b13media.mock.*; import java.io.IOException; import java.io.StringWriter; import java.io.PrintWriter; /* * Date: 20-Oct-2002 */ public class AddressBookServletTest extends TestCase { private final StringWriter page = new StringWriter(); private Mock requestMock = new Mock("request"); private Mock responseMock = new Mock("response"); private AddressBookServlet servlet = new AddressBookServlet(); public AddressBookServletTest(String name) { super(name); } public void testMissingName() throws IOException, ServletException { requestMock.setupResult("getMethod", "GET"); requestMock.expectReturn("getParameter", P.arg(P.eq("name")), null); responseMock.expectVoid("setContentType", P.arg(P.eq("text/plain"))); responseMock.order("setContentType", "getWriter"); responseMock.setupResult("getWriter", new PrintWriter(page)); callServlet(); requestMock.verify(); responseMock.verify(); assertEquals("should be error", "No name", page.toString().trim()); } private void callServlet() throws IOException, ServletException { servlet.service((HttpServletRequest)requestMock.createInterface(HttpServletRequest.class), (HttpServletResponse)responseMock.createInterface(HttpServletResponse.class)); } } --- NEW FILE: AddressBookServlet.java --- package nostone.addressbookWithJMock; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; /* */ public class AddressBookServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); response.setContentType("text/plain"); PrintWriter wr = response.getWriter(); wr.println("No name"); } } |
From: Steve F. <sm...@us...> - 2002-10-20 23:28:57
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook In directory usw-pr-cvs1:/tmp/cvs-serv30492/src/java/nostone/addressbook Modified Files: AddressBookServlet.java AddressBookServletTest.java Log Message: added more tests for one entry Index: AddressBookServlet.java =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook/AddressBookServlet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AddressBookServlet.java 8 Sep 2002 15:18:57 -0000 1.3 +++ AddressBookServlet.java 20 Oct 2002 23:28:54 -0000 1.4 @@ -7,15 +7,22 @@ import java.io.IOException; public class AddressBookServlet extends HttpServlet { - public AddressBookServlet() { - } - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); response.setContentType("text/plain"); response.getWriter().println( - name == null ? "No address found" : "surname@domain"); + lookupName(name)); + } + + private String lookupName(String name) { + if (name == null) { + return "No name"; + } else if (name.equals("somebody")) { + return "somebody@domain"; + } else { + return "No address found"; + } } } Index: AddressBookServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook/AddressBookServletTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AddressBookServletTest.java 8 Sep 2002 15:18:57 -0000 1.3 +++ AddressBookServletTest.java 20 Oct 2002 23:28:54 -0000 1.4 @@ -10,35 +10,54 @@ public class AddressBookServletTest extends TestCase { private final StringWriter page = new StringWriter(); - private final ExpectationValue requestParameterName = new ExpectationValue("Request parameter name"); private HttpServletResponse mockResponse = new NullHttpServletResponse() { - private String contentType; - public void setContentType(String aContentType) { - assertEquals("Content type", "text/plain", aContentType); - contentType = aContentType; - } - - public PrintWriter getWriter() throws IOException { - assertNotNull("Should have content type", contentType); - return new PrintWriter(page); - } - }; + private String contentType; + + public void setContentType(String aContentType) { + assertEquals("Content type", "text/plain", aContentType); + contentType = aContentType; + } + + public PrintWriter getWriter() throws IOException { + assertNotNull("Should have content type", contentType); + return new PrintWriter(page); + } + }; + private String requestParameter; + private final ExpectationValue requestParameterName = new ExpectationValue("Request parameter name"); private AddressBookServlet servlet = new AddressBookServlet(); + private HttpServletRequest mockRequest = new NullHttpServletRequest() { + public String getMethod() { + return "GET"; + } + + public String getProtocol() { + return "HTTP/1.1"; + } + + public String getParameter(String parameterName) { + requestParameterName.setActual(parameterName); + return requestParameter; + } + }; public AddressBookServletTest(String name) { super(name); } - public void testNoEntries() throws ServletException, IOException { + public void testMissingName() throws ServletException, IOException { + requestParameterName.setExpected("name"); + + servlet.service(mockRequest, mockResponse); + + requestParameterName.verify(); + assertEquals("Should be error message", "No name", page.toString().trim()); + } + + public void testFindNoAddress() throws ServletException, IOException { requestParameterName.setExpected("name"); - HttpServletRequest mockRequest = new NullHttpServletRequest() { - public String getMethod() { - return "GET"; - } - public String getProtocol() { - return "HTTP/1.1"; - } - }; + + requestParameter = "nobody"; servlet.service(mockRequest, mockResponse); requestParameterName.verify(); @@ -47,23 +66,12 @@ public void testFindOneAddress() throws ServletException, IOException { requestParameterName.setExpected("name"); - HttpServletRequest mockRequest = new NullHttpServletRequest() { - public String getMethod() { - return "GET"; - } - public String getProtocol() { - return "HTTP/1.1"; - } - - public String getParameter(String parameterName) { - requestParameterName.setActual(parameterName); - return "surname"; - } - }; + + requestParameter = "somebody"; servlet.service(mockRequest, mockResponse); requestParameterName.verify(); - assertEquals("Should be empty response", "surname@domain", page.toString().trim()); + assertEquals("Should be expected address", "somebody@domain", page.toString().trim()); } } |
From: Steve F. <sm...@us...> - 2002-10-20 23:27:49
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbookWithJMock In directory usw-pr-cvs1:/tmp/cvs-serv29993/src/java/nostone/addressbookWithJMock Log Message: Directory /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbookWithJMock added to the repository |
From: Steve F. <sm...@us...> - 2002-10-20 23:26:26
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv29417/doc/html Modified Files: index.html Log Message: Reformatted Added info about latest drop Index: index.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/index.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- index.html 29 Aug 2002 12:17:21 -0000 1.1 +++ index.html 20 Oct 2002 23:26:23 -0000 1.2 @@ -1,109 +1,92 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> + <title>MockObjects Home</title> +</head> +<body> + <h1>Project description and goals</h1> -<p> -The <a href= "http://www.mockobjects.com">Mock Objects</a> project is a -generic unit testing framework whose goal is to facilitate developing -unit tests in the mock object style. The goal of this project is to provide: -</p> + +<p>The <a href="http://www.mockobjects.com">Mock Objects</a> project is a +generic unit testing framework whose goal is to facilitate developing unit +tests in the mock object style. The goal of this project is to provide:</p> + <ul> - <li> -A core mock objects framework. This is a library of code that supports + <li>A core mock objects framework. This is a library of code that supports the implementation of mock objects. It is based around a set of expectation -classes for values and collections. There are also various other classes to -make mock objects easier to write or to use. - </li> - <li> -A methodology for developing and using mock objects. - </li> - <li> -A default set of mock implementation for the standard Java platform APIs. -We have made a start on packages such as servlets, sql, and io. - </li> - <li> -Mock implementations for more specialised libraries, particularly third +classes for values and collections. There are also various other classes +to make mock objects easier to write or to use. </li> + <li>A methodology for developing and using mock objects. </li> + <li>A default set of mock implementation for the standard Java platform +APIs. We have made a start on packages such as servlets, sql, and io. </li> + <li>Mock implementations for more specialised libraries, particularly third party products. So far, we have started on ATG Dynamo and IBM's VisualAge -for Java tools API. - </li> - <li> -A community for exchanging ideas on anything related to unit testing, with -a bias towards Mock Objects. - </li> +for Java tools API. </li> + <li>A community for exchanging ideas on anything related to unit testing, +with a bias towards Mock Objects. </li> </ul> -<p> -Our larger goal is to make -<a href= "www.mockobjects.com">www.mockobjects.com</a> the point of -reference for ideas and tools for unit testing particularly based on Mock -Objects. Our first implementation is in Java, largely because that's what -we've been working in, but also because it has a stable set of APIs that -are suitable for writing Mock Objects. We have applied these techniques -to other environments and intend to publish the results here. -</p> + +<p>Our larger goal is to make<a href="www.mockobjects.com">www.mockobjects.com</a> +the point of reference for ideas and tools for unit testing particularly +based on Mock Objects. Our first implementation is in Java, largely because +that's what we've been working in, but also because it has a stable set of +APIs that are suitable for writing Mock Objects. We have applied these techniques +to other environments and intend to publish the results here.</p> + <h1>Latest news and announcements</h1> -<table cellpadding="2" cellspacing="2" border="0" width="100%"> - <tr> - <td align="left" valign="top" rowspan=" - 1" colspan="1" bgcolor="#a0ddf0"> - <span class=" - c11">2002/08/28 </span> - </td> - <td align="left" valign="top" rowspan=" - 1" colspan="1" bgcolor="#a0ddf0"> - <span class="c11">0.4 <a - href=" - http://sourceforge.net/project/showfiles.php?group_id=18189&release_id=101526">release</a> - available. Kinda like the interim release but better.</span> - </td> +<table cellpadding="2" cellspacing="2" border="0" width="100%"> + <tbody> + <tr align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> + <td valign="top"><span class=" c11">2002/10/20</span> </td> + <td valign="top"><span class="c11">0.5 Reorganised the <a + href="http://sourceforge.net/project/showfiles.php?group_id=18189&release_id=116303">release</a> + structure. Broke up the jar into several smaller jars: <code>core</code>, + <code>jdk</code>, <code>j2ee</code>, and <code>alt</code>, with combinations +of versions of jdk and j2ee.</span> </td> + </tr> + <tr> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class=" c11">2002/08/28 </span> + </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">0.4 <a + href="http://sourceforge.net/project/showfiles.php?group_id=18189&release_id=101526">release</a> + available. Kinda like the interim release but better.</span> </td> </tr> <tr> - <td align="left" valign="top" rowspan= - "1" colspan="1" bgcolor="#a0ddf0"> - <span class= - "c11">2002/05/02 </span> - </td> - <td align="left" valign="top" rowspan= - "1" colspan="1" bgcolor="#a0ddf0"> - <span class="c11">Interim release <a - href= - "mockobjects-cvsroot.tar.gz">Tarball</a> - available. Not an official release - but this snap shot has a lot of new - mocks in it and is a must for j2ee - development.</span> - </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">2002/05/02 </span> </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">Interim release <a + href="mockobjects-cvsroot.tar.gz">Tarball</a> available. Not an official +release but this snap shot has a lot of new mocks in it and is +a must for j2ee development.</span> </td> </tr> <tr> - <td align="left" valign="top" rowspan= - "1" colspan="1" bgcolor="#a0ddf0"> - <span class= - "c11">2001/09/08 </span> - </td> - <td align="left" valign="top" rowspan= - "1" colspan="1" bgcolor="#a0ddf0"> - <span class="c11">Added a new section - for papers on Mock - Objects </span> - </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">2001/09/08 </span> </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">Added a new section for +papers on Mock Objects </span> </td> </tr> <tr> - <td align="left" valign="top" rowspan= - "1" colspan="1" bgcolor="#a0ddf0"> - <span class= - "c11">2001/08/06 </span> - </td> - <td align="left" valign="top" rowspan= - "1" colspan="1" bgcolor="#a0ddf0"> - <span class="c11">The Mock Objects - project now has a user web site. We - are committed to building a thriving - framework and community around Mock - Objects. Of course we're looking for - help ... </span> - </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">2001/08/06 </span> </td> + <td align="left" valign="top" rowspan="1" colspan="1" + bgcolor="#a0ddf0"> <span class="c11">The Mock Objects project +now has a user web site. We are committed to building a thriving + framework and community around Mock Objects. Of course we're looking +for help ... </span> </td> </tr> + </tbody> </table> + <p class="c9"> - <a href="http://sourceforge.net"><img - align="right" hspace="4" vspace="4" - border="0" alt="SourceForge Logo" src= - "http://sourceforge.net/sflogo.php?group_id=18189"></a> + <a href="http://sourceforge.net/projects/mockobjects/"> + <img align="right" hspace="4" vspace="4" style="border: 0px solid ; width: 88px; height: 31px;" + alt="SourceForge Logo" src="http://sourceforge.net/sflogo.php?group_id=18189"></a> </p> +</body> +</html> |