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