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(); } } |