KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > expectation > ExpectationSegment


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.expectation;
4
5
6 public class ExpectationSegment extends AbstractExpectation
7 {
8     private String JavaDoc myExpectedSegment;
9     private String JavaDoc myActualString;
10
11     public ExpectationSegment( String JavaDoc name ) {
12         super(name);
13         clearActual();
14     }
15
16     public void clearActual() {
17         myActualString = null;
18     }
19
20     public void setActual( String JavaDoc aString ) {
21         myActualString = aString;
22         if (shouldCheckImmediately()) {
23             verify();
24         }
25     }
26
27     public void setExpected( String JavaDoc segment ) {
28         myExpectedSegment = segment;
29         setHasExpectations();
30     }
31
32     public void setExpectNothing() {
33         myActualString = null;
34         setExpected(null);
35     }
36
37     public void verify() {
38         if (hasExpectations()) {
39             if (null == myExpectedSegment) {
40                 AssertMo.assertNull("Expecting nothing", myActualString);
41             } else {
42                 AssertMo.assertIncludes("Should include string segment",
43                                         myExpectedSegment,
44                                         myActualString);
45             }
46         }
47     }
48 }
49
Popular Tags