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: | 119 |  | Methods: | 11
| NCLOC: | 97 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ExpectedInvocation.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.lang.reflect.Method;
8 |  | import java.util.ArrayList;
9 |  | import java.util.Iterator;
10 |  | import java.util.List;
11 |  |
12 |  | import org.easymock.IArgumentMatcher;
13 |  | import org.easymock.internal.matchers.Equals;
14 |  |
15 |  | public class ExpectedInvocation {
16 |  |
17 |  | private final Invocation invocation;
18 |  |
19 |  | @SuppressWarnings("deprecation")
20 |  | private final org.easymock.ArgumentsMatcher matcher;
21 |  |
22 |  | private final List<IArgumentMatcher> matchers;
23 |  |
24 | 452 | public ExpectedInvocation(Invocation invocation,
25 |  | List<IArgumentMatcher> matchers) {
26 | 452 | this(invocation, matchers, null);
27 |  | }
28 |  |
29 | 491 | private ExpectedInvocation(Invocation invocation,
30 |  | List<IArgumentMatcher> matchers, @SuppressWarnings("deprecation")
31 |  | org.easymock.ArgumentsMatcher matcher) {
32 | 491 | this.invocation = invocation;
33 | 491 | this.matcher = matcher;
34 | 491 | this.matchers = (matcher == null) ? createMissingMatchers(invocation,
35 |  | matchers) : null;
36 |  | }
37 |  |
38 | 453 | private List<IArgumentMatcher> createMissingMatchers(Invocation invocation,
39 |  | List<IArgumentMatcher> matchers) {
40 | 453 | if (matchers != null) {
41 | 125 | if (matchers.size() != invocation.getArguments().length) {
42 | 1 | throw new IllegalStateException(""
43 |  | + invocation.getArguments().length
44 |  | + " matchers expected, " + matchers.size()
45 |  | + " recorded.");
46 |  | }
47 |  | ;
48 | 124 | return matchers;
49 |  | }
50 | 328 | List<IArgumentMatcher> result = new ArrayList<IArgumentMatcher>();
51 | 328 | for (Object argument : invocation.getArguments()) {
52 | 350 | result.add(new Equals(argument));
53 |  | }
54 | 328 | return result;
55 |  | }
56 |  |
57 | 646 | public boolean equals(Object o) {
58 | 646 | if (o == null || !this.getClass().equals(o.getClass()))
59 | 1 | return false;
60 |  |
61 | 645 | ExpectedInvocation other = (ExpectedInvocation) o;
62 | 645 | return this.invocation.equals(other.invocation)
63 |  | && ((this.matcher == null && other.matcher == null) || (this.matcher != null && this.matcher
64 |  | .equals(other.matcher)))
65 |  | && ((this.matchers == null && other.matchers == null) || (this.matchers != null && this.matchers
66 |  | .equals(other.matchers)));
67 |  | }
68 |  |
69 | 1 | public int hashCode() {
70 | 1 | return invocation.hashCode();
71 |  | }
72 |  |
73 | 1594 | public boolean matches(Invocation actual) {
74 | 1594 | return matchers != null ? this.invocation.getMock().equals(
75 |  | actual.getMock())
76 |  | && this.invocation.getMethod().equals(actual.getMethod())
77 |  | && matches(actual.getArguments()) : this.invocation.matches(
78 |  | actual, matcher);
79 |  | }
80 |  |
81 | 808 | private boolean matches(Object[] arguments) {
82 | 808 | if (arguments.length != matchers.size()) {
83 | 20 | return false;
84 |  | }
85 | 788 | for (int i = 0; i < arguments.length; i++) {
86 | 864 | if (!matchers.get(i).matches(arguments[i])) {
87 | 272 | return false;
88 |  | }
89 |  | }
90 | 516 | return true;
91 |  | }
92 |  |
93 | 229 | public String toString() {
94 | 229 | return matchers != null ? myToString() : invocation.toString(matcher);
95 |  | }
96 |  |
97 | 219 | private String myToString() {
98 | 219 | StringBuffer result = new StringBuffer();
99 | 219 | result.append(invocation.getMockAndMethodName());
100 | 219 | result.append("(");
101 | 219 | for (Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
102 | 241 | it.next().appendTo(result);
103 | 238 | if (it.hasNext()) {
104 | 51 | result.append(", ");
105 |  | }
106 |  | }
107 | 216 | result.append(")");
108 | 216 | return result.toString();
109 |  | }
110 |  |
111 | 1163 | public Method getMethod() {
112 | 1163 | return invocation.getMethod();
113 |  | }
114 |  |
115 | 38 | public ExpectedInvocation withMatcher(@SuppressWarnings("deprecation")
116 |  | org.easymock.ArgumentsMatcher matcher) {
117 | 38 | return new ExpectedInvocation(invocation, null, matcher);
118 |  | }
119 |  | }