Clover Coverage Report - EasyMock 3.0
Coverage timestamp: sam. mai 8 2010 14:37:27 CEST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
39   113   16   6,5
14   73   0,41   6
6     2,67  
1    
 
  UnorderedBehavior       Line # 26 39 0% 16 0 100% 1.0
 
  (494)
 
1    /**
2    * Copyright 2001-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package org.easymock.internal;
18   
19    import java.io.Serializable;
20    import java.util.ArrayList;
21    import java.util.List;
22   
23    /**
24    * @author OFFIS, Tammo Freese
25    */
 
26    public class UnorderedBehavior implements Serializable {
27   
28    private static final long serialVersionUID = 2185791334636597469L;
29   
30    private final List<ExpectedInvocationAndResults> results = new ArrayList<ExpectedInvocationAndResults>();
31   
32    private final boolean checkOrder;
33   
 
34  790 toggle public UnorderedBehavior(final boolean checkOrder) {
35  790 this.checkOrder = checkOrder;
36    }
37   
 
38  1266 toggle public void addExpected(final ExpectedInvocation expected, final Result result, final Range count) {
39  1266 for (final ExpectedInvocationAndResults entry : results) {
40  1492 if (entry.getExpectedInvocation().equals(expected)) {
41  88 entry.getResults().add(result, count);
42  84 return;
43    }
44    }
45  1178 final Results list = new Results();
46  1178 list.add(result, count);
47  1178 results.add(new ExpectedInvocationAndResults(expected, list));
48    }
49   
 
50  1762 toggle public Result addActual(final Invocation actual) {
51  1762 for (final ExpectedInvocationAndResults entry : results) {
52  3356 try {
53    // if no results are available anymore, it's worthless to try to match
54  3356 if (!entry.getResults().hasResults()) {
55  1558 continue;
56    }
57    // if it doesn't match, keep searching
58  1798 if (!entry.getExpectedInvocation().matches(actual)) {
59  536 continue;
60    }
61  1262 final Result result = entry.getResults().next();
62    // actual and expected matched, validate the capture
63  1262 actual.validateCaptures();
64  1262 return result;
65    } finally {
66    // reset the capture (already validated or expected didn't
67    // matched)
68  3356 actual.clearCaptures();
69    }
70    }
71  500 return null;
72    }
73   
 
74  996 toggle public boolean verify() {
75  996 for (final ExpectedInvocationAndResults entry : results) {
76  1454 if (!entry.getResults().hasValidCallCount()) {
77  228 return false;
78    }
79    }
80  768 return true;
81    }
82   
 
83  250 toggle public List<ErrorMessage> getMessages(final Invocation invocation) {
84  250 final List<ErrorMessage> messages = new ArrayList<ErrorMessage>(results.size());
85  250 for (final ExpectedInvocationAndResults entry : results) {
86  294 final boolean unordered = !checkOrder;
87  294 final boolean validCallCount = entry.getResults().hasValidCallCount();
88  294 final boolean match = invocation != null && entry.getExpectedInvocation().matches(invocation);
89   
90  294 if (unordered && validCallCount && !match) {
91  58 continue;
92    }
93   
94  236 final ErrorMessage message = new ErrorMessage(match, entry.toString(), entry.getResults()
95    .getCallCount());
96  234 messages.add(message);
97    }
98  248 return messages;
99   
100    }
101   
 
102  650 toggle public boolean allowsExpectedInvocation(final ExpectedInvocation expected, final boolean checkOrder) {
103  650 if (this.checkOrder != checkOrder) {
104  4 return false;
105  646 } else if (results.isEmpty() || !this.checkOrder) {
106  464 return true;
107    } else {
108  182 final ExpectedInvocation lastMethodCall = results.get(results.size() - 1).getExpectedInvocation();
109  182 return lastMethodCall.equals(expected);
110    }
111    }
112   
113    }