1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.expectation;
3
4 import junit.framework.AssertionFailedError;
5 import org.jmock.AbstractTestCase;
6
7 public class TestExpectationSegment extends AbstractTestCase {
8
9 private ExpectationSegment myExpectation;
10
11 public void setUp() {
12 myExpectation = new ExpectationSegment("Expectation segment");
13 }
14
15 public void testExpectNothing() {
16 myExpectation.setExpectNothing();
17
18 assertTrue("Should have an expectation", myExpectation.hasExpectations());
19 }
20
21 public void testExpectNothingFail() {
22 myExpectation.setExpectNothing();
23
24 boolean hasThrownException = false;
25 try {
26 myExpectation.setActual("some string");
27 } catch (AssertionFailedError ex) {
28 hasThrownException = true;
29 }
30
31 assertTrue("Should fail fast", hasThrownException);
32 }
33
34 public void testFailOnVerify() {
35 myExpectation.setExpected("a segment");
36 myExpectation.setFailOnVerify();
37
38 myExpectation.setActual("string without stuff");
39 assertVerifyFails(myExpectation);
40 }
41
42 public void testFailsImmediately() {
43
44 boolean hasThrownException = false;
45 myExpectation.setExpected("inner");
46 try {
47 myExpectation.setActual("String not containing segment");
48 } catch (AssertionFailedError expected) {
49 hasThrownException = true;
50 }
51
52 assertTrue("Should have thrown exception", hasThrownException);
53 }
54
55 public void testFlushActual() {
56 myExpectation.setActual("a string");
57
58 myExpectation.setExpectNothing();
59
60 myExpectation.verify();
61 }
62
63 public void testHasNoExpectations() {
64 myExpectation.setActual("a string");
65
66 assertTrue("Has no expectations", !myExpectation.hasExpectations());
67 }
68
69 public void testPasses() {
70
71 myExpectation.setExpected("inner");
72 myExpectation.setActual("String containing inner segment");
73
74 myExpectation.verify();
75 }
76 }
This page was automatically generated by Maven