EasyMock 2.3

Clover coverage report - EasyMock 2.3
Coverage timestamp: mar. juil. 10 2007 02:46:04 CEST
FRAMES NO FRAMES

file stats: | LOC: | 92 |  | Methods: | 7
| NCLOC: | 74 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

UnorderedBehavior.java

100%

100%

100%

100%

1 |  | /*
2 |  | * Copyright (c) 2001-2007 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.util.ArrayList;
8 |  | import java.util.List;
9 |  |
10 |  | public class UnorderedBehavior {
11 |  |
12 |  | private final List<ExpectedInvocationAndResults> results = new ArrayList<ExpectedInvocationAndResults>();
13 |  |
14 |  | private final boolean checkOrder;
15 |  |
16 | 240 | public UnorderedBehavior(boolean checkOrder) {
17 | 240 | this.checkOrder = checkOrder;
18 |  | }
19 |  |
20 | 401 | public void addExpected(ExpectedInvocation expected, Result result,
21 |  | Range count) {
22 | 401 | for (ExpectedInvocationAndResults entry : results) {
23 | 580 | if (entry.getExpectedInvocation().equals(expected)) {
24 | 39 | entry.getResults().add(result, count);
25 | 37 | return;
26 |  | }
27 |  | }
28 | 362 | Results list = new Results();
29 | 362 | list.add(result, count);
30 | 362 | results.add(new ExpectedInvocationAndResults(expected, list));
31 |  | }
32 |  |
33 | 582 | public Result addActual(Invocation actual) {
34 | 582 | for (ExpectedInvocationAndResults entry : results) {
35 | 1196 | if (!entry.getExpectedInvocation().matches(actual)) {
36 | 749 | continue;
37 |  | }
38 | 447 | Result result = entry.getResults().next();
39 | 447 | if (result != null) {
40 | 412 | return result;
41 |  | }
42 |  | }
43 | 170 | return null;
44 |  | }
45 |  |
46 | 320 | public boolean verify() {
47 | 320 | for (ExpectedInvocationAndResults entry : results) {
48 | 477 | if (!entry.getResults().hasValidCallCount()) {
49 | 84 | return false;
50 |  | }
51 |  | }
52 | 236 | return true;
53 |  | }
54 |  |
55 | 151 | @Override
56 |  | public String toString() {
57 | 151 | return toString(null);
58 |  | }
59 |  |
60 | 321 | public String toString(Invocation invocation) {
61 | 321 | StringBuffer result = new StringBuffer();
62 | 321 | for (ExpectedInvocationAndResults entry : results) {
63 | 516 | boolean unordered = !checkOrder;
64 | 516 | boolean validCallCount = entry.getResults().hasValidCallCount();
65 | 516 | boolean match = invocation != null
66 |  | && entry.getExpectedInvocation().matches(invocation);
67 |  |
68 | 516 | if (unordered && validCallCount && !match) {
69 | 291 | continue;
70 |  | }
71 | 225 | result.append("\n " + entry.toString());
72 | 224 | if (match) {
73 | 34 | result.append(" (+1)");
74 |  | }
75 |  | }
76 | 320 | return result.toString();
77 |  | }
78 |  |
79 | 222 | public boolean allowsExpectedInvocation(ExpectedInvocation expected,
80 |  | boolean checkOrder) {
81 | 222 | if (this.checkOrder != checkOrder) {
82 | 2 | return false;
83 | 220 | } else if (results.isEmpty() || !this.checkOrder) {
84 | 156 | return true;
85 |  | } else {
86 | 64 | ExpectedInvocation lastMethodCall = results.get(results.size() - 1)
87 |  | .getExpectedInvocation();
88 | 64 | return lastMethodCall.equals(expected);
89 |  | }
90 |  | }
91 |  |
92 |  | }