Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
37   95   22   5,29
16   76   0,59   7
7     3,14  
1    
 
 
  UnorderedBehavior       Line # 11 37 22 100% 1.0
 
  (187)
 
1    /*
2    * Copyright (c) 2001-2008 OFFIS, Tammo Freese.
3    * This program is made available under the terms of the MIT License.
4    */
5    package org.easymock.internal;
6   
7    import java.io.Serializable;
8    import java.util.ArrayList;
9    import java.util.List;
10   
 
11    public class UnorderedBehavior implements Serializable {
12   
13    private static final long serialVersionUID = 2185791334636597469L;
14   
15    private final List<ExpectedInvocationAndResults> results = new ArrayList<ExpectedInvocationAndResults>();
16   
17    private final boolean checkOrder;
18   
 
19  261 toggle public UnorderedBehavior(boolean checkOrder) {
20  261 this.checkOrder = checkOrder;
21    }
22   
 
23  439 toggle public void addExpected(ExpectedInvocation expected, Result result,
24    Range count) {
25  439 for (ExpectedInvocationAndResults entry : results) {
26  615 if (entry.getExpectedInvocation().equals(expected)) {
27  38 entry.getResults().add(result, count);
28  36 return;
29    }
30    }
31  401 Results list = new Results();
32  401 list.add(result, count);
33  401 results.add(new ExpectedInvocationAndResults(expected, list));
34    }
35   
 
36  643 toggle public Result addActual(Invocation actual) {
37  643 for (ExpectedInvocationAndResults entry : results) {
38  1296 if (!entry.getExpectedInvocation().matches(actual)) {
39  800 continue;
40    }
41  496 Result result = entry.getResults().next();
42  496 if (result != null) {
43  457 return result;
44    }
45    }
46  186 return null;
47    }
48   
 
49  350 toggle public boolean verify() {
50  350 for (ExpectedInvocationAndResults entry : results) {
51  526 if (!entry.getResults().hasValidCallCount()) {
52  85 return false;
53    }
54    }
55  265 return true;
56    }
57   
 
58  165 toggle @Override
59    public String toString() {
60  165 return toString(null);
61    }
62   
 
63  351 toggle public String toString(Invocation invocation) {
64  351 StringBuffer result = new StringBuffer();
65  351 for (ExpectedInvocationAndResults entry : results) {
66  565 boolean unordered = !checkOrder;
67  565 boolean validCallCount = entry.getResults().hasValidCallCount();
68  565 boolean match = invocation != null
69    && entry.getExpectedInvocation().matches(invocation);
70   
71  565 if (unordered && validCallCount && !match) {
72  325 continue;
73    }
74  240 result.append("\n " + entry.toString());
75  239 if (match) {
76  38 result.append(" (+1)");
77    }
78    }
79  350 return result.toString();
80    }
81   
 
82  241 toggle public boolean allowsExpectedInvocation(ExpectedInvocation expected,
83    boolean checkOrder) {
84  241 if (this.checkOrder != checkOrder) {
85  2 return false;
86  239 } else if (results.isEmpty() || !this.checkOrder) {
87  173 return true;
88    } else {
89  66 ExpectedInvocation lastMethodCall = results.get(results.size() - 1)
90    .getExpectedInvocation();
91  66 return lastMethodCall.equals(expected);
92    }
93    }
94   
95    }