001: package net.sf.mockcreator;
002:
003: import junit.framework.AssertionFailedError;
004: import net.sf.mockcreator.expectable.Ignore;
005:
006: public class DummyTest extends TestCase {
007: MockDummy mock;
008:
009: public DummyTest(String name) {
010: super (name);
011: }
012:
013: public void setUp() throws Exception {
014: super .setUp();
015: mock = new MockDummy();
016: }
017:
018: public void testImplementsMockBase() throws Exception {
019: MockBase mb = (MockBase) mock;
020: }
021:
022: public void testNullNonDefault() throws Exception {
023: mock.expectZeroOrMoreToString().returns("Default");
024: mock.expectZeroOrMoreToString("NonDefault").returns(null);
025:
026: assertNull(mock.toString("NonDefault"));
027: }
028:
029: public void testNonDefault() throws Exception {
030: mock.expectZeroOrMoreToString().returns("Default");
031: mock.expectZeroOrMoreToString("NonDefault").returns("Bar");
032:
033: assertEquals("Bar", mock.toString("NonDefault"));
034: assertEquals("Default", mock.toString("Unexpected"));
035: }
036:
037: public void testDummy() throws Exception {
038: mock.expectZeroOrMoreToString("1").returns("Foo");
039: mock.expectZeroOrMoreToString("2").returns("Bar");
040: mock.expectZeroOrMoreToString(null).returns("Baz");
041: mock.expectZeroOrMoreToString().returns("Boom");
042:
043: assertEquals("Foo", mock.toString("1"));
044: assertEquals("Bar", mock.toString("2"));
045: assertEquals("Foo", mock.toString("1"));
046: assertEquals("Boom", mock.toString("Unexpected1"));
047: assertEquals("Baz", mock.toString(null));
048:
049: assertEquals("Boom", mock.toString("Unexpected2"));
050: }
051:
052: public void testDummyEx() throws Exception {
053: mock.expectZeroOrMoreToString("1").throwable(
054: new IllegalArgumentException("1"));
055: mock.expectZeroOrMoreToString("2").throwable(
056: new IllegalStateException("2"));
057: mock.expectZeroOrMoreToString(null).throwable(
058: new RuntimeException());
059: mock.expectZeroOrMoreToString().throwable(
060: new AssertionFailedError());
061:
062: try {
063: mock.toString("1");
064: fail();
065: } catch (IllegalArgumentException ex) {
066: }
067:
068: try {
069: mock.toString("2");
070: fail();
071: } catch (IllegalStateException ex) {
072: }
073:
074: try {
075: mock.toString("1");
076: fail();
077: } catch (IllegalArgumentException ex) {
078: }
079:
080: try {
081: mock.toString(null);
082: fail();
083: } catch (RuntimeException ex) {
084: }
085:
086: try {
087: mock.toString("XXX");
088: fail();
089: } catch (AssertionFailedError ex) {
090: }
091: }
092:
093: public void testAcceptDummy() throws Exception {
094: mock.expectAfoo("5", 7).returns(8);
095: mock.acceptAfoo("5", new Ignore()).returns(8);
096:
097: mock.expectZeroOrMoreAfoo("1", 2).returns(3);
098:
099: mock.acceptZeroOrMoreAfoo(new Ignore(), new Integer(3))
100: .returns(8);
101: mock.acceptZeroOrMoreAfoo("yahoo", new Ignore()).throwable(
102: new IllegalArgumentException());
103:
104: mock.expectZeroOrMoreAfoo().returns(77);
105:
106: assertEquals(77, mock.afoo("zz", 5)); // matches 4
107: assertEquals(3, mock.afoo("1", 2)); // matches 1
108: assertEquals(8, mock.afoo("1", 3)); // matches 2
109:
110: try {
111: mock.afoo("yahoo", 111);
112: fail();
113: } catch (IllegalArgumentException ex) {
114: }
115: }
116:
117: public void testAmbiguousDummy() throws Exception {
118: mock.expectZeroOrMoreAfoo("1", 2).returns(3); // more specific
119: mock.acceptZeroOrMoreAfoo(new Ignore(), new Integer(2))
120: .returns(4);
121:
122: assertEquals(3, mock.afoo("1", 2));
123: }
124:
125: public void testAmbiguousDummyBackorder() throws Exception {
126: mock.acceptZeroOrMoreAfoo(new Ignore(), new Integer(2))
127: .returns(4);
128: mock.expectZeroOrMoreAfoo("1", 2).returns(3); // more specific
129: assertEquals(3, mock.afoo("1", 2));
130: }
131:
132: public void testDummyReturnable() throws Exception {
133: // mock.acceptAfoo(null,null).returns(111);
134: //mock.acceptZeroOrMoreAfoo(new Ignore(), new Integer(2), 4);
135: //mock.expectZeroOrMoreAfoo("1", 2, 3).throwable(null); // more specific
136: //assertEquals(3,mock.afoo("1", 2));
137: }
138: }
|