001: package net.sf.mockcreator;
002:
003: import java.util.HashSet;
004:
005: import net.sf.mockcreator.exceptions.MockException;
006: import net.sf.mockcreator.expectable.Ignore;
007:
008: public class VoidVoidTest extends TestCase {
009: MockVoidVoid mock;
010: MockComplex complex;
011:
012: public VoidVoidTest(String name) {
013: super (name);
014: }
015:
016: public void setUp() throws Exception {
017: super .setUp();
018: MockCore.reset();
019: mock = new MockVoidVoid();
020: complex = new MockComplex();
021: }
022:
023: public IllegalArgumentException throwable() {
024: return new IllegalArgumentException("oops");
025: }
026:
027: public void testExpect() throws Exception {
028: mock.expectVoidMethod();
029: mock.voidMethod();
030:
031: MockCore.verify();
032: }
033:
034: public void testExpectThrow() throws Exception {
035: mock.expectVoidMethod().throwable(throwable());
036:
037: try {
038: mock.voidMethod();
039: fail();
040: } catch (IllegalArgumentException ex) {
041: }
042:
043: MockCore.verify();
044: }
045:
046: public void testAccept() throws Exception {
047: complex.acceptGetArr(new HashSet());
048: complex.getArr(new HashSet());
049:
050: MockCore.verify();
051: }
052:
053: public void testAcceptThrow() throws Exception {
054: complex.acceptGetArr(new Ignore()).throwable(throwable());
055:
056: try {
057: complex.getArr(new HashSet());
058: fail();
059: } catch (IllegalArgumentException ex) {
060: }
061:
062: MockCore.verify();
063: }
064:
065: public void testDummy() throws Exception {
066: mock.expectZeroOrMoreVoidMethod().throwable(throwable());
067:
068: try {
069: mock.voidMethod();
070: fail();
071: } catch (IllegalArgumentException ex) {
072: }
073:
074: try {
075: mock.voidMethod();
076: fail();
077: } catch (IllegalArgumentException ex) {
078: }
079:
080: MockCore.verify();
081: }
082:
083: public void ZtestExpectAndDummy() throws Exception {
084: mock.expectVoidMethod().throwable(throwable());
085:
086: try {
087: mock.expectZeroOrMoreVoidMethod().throwable(throwable());
088: fail();
089: } catch (MockException ex) {
090: }
091: }
092:
093: public void ZtestAcceptAndDummy() throws Exception {
094: complex.acceptGetArr(new Ignore()).throwable(throwable());
095:
096: try {
097: complex.expectZeroOrMoreGetArr().throwable(throwable());
098: fail();
099: } catch (MockException ex) {
100: }
101: }
102:
103: public void testUnsetuped() throws Exception {
104: try {
105: mock.voidMethod();
106: fail();
107: } catch (MockException ex) {
108: }
109: }
110:
111: public void testExpectedNotCalled() throws Exception {
112: mock.expectVoidMethod();
113:
114: try {
115: MockCore.verify();
116: fail();
117: } catch (MockException ex) {
118: }
119: }
120:
121: public void testVerifyNothing() throws Exception {
122: MockCore.verify();
123: }
124: }
|