01: package org.jingle.mocquer.internal;
02:
03: import org.jingle.mocquer.AssertionFailedError;
04:
05: /**
06: * This class is a strict implementation of BehaviorSet interface
07: *
08: * @author JianLu
09: * @version 1.0 2004-10-27
10: * @since 1.0
11: */
12: public class StrictBehaviorSet extends NormalBehaviorSet {
13:
14: /**
15: * (non-Javadoc)
16: * @see org.jingle.mocquer.internal.NormalBehaviorSet#findBehavior(org.jingle.mockobject.internal.MockBehavior)
17: */
18: protected MockBehavior findBehavior(MockBehavior behavior) {
19: MockBehavior ret = null;
20: boolean firstTime = true;
21: for (int i = 1; i <= behaviorList.size(); i++) {
22: MockBehavior item = (MockBehavior) behaviorList.get(i - 1);
23: if (!item.isUsed()) {
24: if (!item.getMethod().equals(behavior.getMethod())
25: || !item.getMatcher().matches(
26: item.getArguments(),
27: behavior.getArguments())) {
28: if (firstTime) {
29: if (!item.getRange().inRange(
30: item.getActualTimes()))
31: throw new AssertionFailedError(
32: "According to the order, "
33: + item
34: + " is expected, but it is "
35: + behavior + " actually.");
36: item.setUsed();
37: firstTime = false;
38: } else
39: throw new AssertionFailedError(
40: "According to the order, " + item
41: + " is expected, but it is "
42: + behavior + " actually.");
43: } else {
44: ret = item;
45: break;
46: }
47: }
48: }
49: return ret;
50: }
51: }
|