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
32   120   17   4
16   86   0,53   8
8     2,12  
1    
 
  ExpectedInvocation       Line # 31 32 0% 17 0 100% 1.0
 
  (579)
 
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.lang.reflect.Method;
21    import java.util.ArrayList;
22    import java.util.Iterator;
23    import java.util.List;
24   
25    import org.easymock.IArgumentMatcher;
26    import org.easymock.internal.matchers.Equals;
27   
28    /**
29    * @author OFFIS, Tammo Freese
30    */
 
31    public class ExpectedInvocation implements Serializable {
32   
33    private static final long serialVersionUID = -5554816464613350531L;
34   
35    private final Invocation invocation;
36   
37    private final List<IArgumentMatcher> matchers;
38   
 
39  1464 toggle public ExpectedInvocation(final Invocation invocation, final List<IArgumentMatcher> matchers) {
40  1464 this.invocation = invocation;
41  1464 this.matchers = createMissingMatchers(invocation, matchers);
42    }
43   
 
44  1464 toggle private List<IArgumentMatcher> createMissingMatchers(final Invocation invocation,
45    final List<IArgumentMatcher> matchers) {
46  1464 if (matchers != null) {
47  412 if (matchers.size() != invocation.getArguments().length) {
48  2 throw new IllegalStateException(
49    ""
50    + invocation.getArguments().length
51    + " matchers expected, "
52    + matchers.size()
53    + " recorded.\n"
54    + "This exception usually occurs when matchers are mixed with raw values when recording a method:\n"
55    + "\tfoo(5, eq(6));\t// wrong\n"
56    + "You need to use no matcher at all or a matcher for every single param:\n"
57    + "\tfoo(eq(5), eq(6));\t// right\n" + "\tfoo(5, 6);\t// also right");
58    }
59  410 return matchers;
60    }
61  1052 final List<IArgumentMatcher> result = new ArrayList<IArgumentMatcher>();
62  1052 for (final Object argument : invocation.getArguments()) {
63  908 result.add(new Equals(argument));
64    }
65  1052 return result;
66    }
67   
 
68  1678 toggle @Override
69    public boolean equals(final Object o) {
70  1678 if (o == null || !this.getClass().equals(o.getClass())) {
71  2 return false;
72    }
73   
74  1676 final ExpectedInvocation other = (ExpectedInvocation) o;
75  1676 return this.invocation.equals(other.invocation)
76    && ((this.matchers == null && other.matchers == null) || (this.matchers != null && this.matchers
77    .equals(other.matchers)));
78    }
79   
 
80  2 toggle @Override
81    public int hashCode() {
82  2 throw new UnsupportedOperationException("hashCode() is not implemented");
83    }
84   
 
85  2338 toggle public boolean matches(final Invocation actual) {
86  2338 return this.invocation.getMock().equals(actual.getMock())
87    && this.invocation.getMethod().equals(actual.getMethod()) && matches(actual.getArguments());
88    }
89   
 
90  1894 toggle private boolean matches(final Object[] arguments) {
91  1894 if (arguments.length != matchers.size()) {
92  4 return false;
93    }
94  3470 for (int i = 0; i < arguments.length; i++) {
95  1948 if (!matchers.get(i).matches(arguments[i])) {
96  368 return false;
97    }
98    }
99  1522 return true;
100    }
101   
 
102  246 toggle @Override
103    public String toString() {
104  246 final StringBuffer result = new StringBuffer();
105  246 result.append(invocation.getMockAndMethodName());
106  246 result.append("(");
107  460 for (final Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
108  220 it.next().appendTo(result);
109  214 if (it.hasNext()) {
110  24 result.append(", ");
111    }
112    }
113  240 result.append(")");
114  240 return result.toString();
115    }
116   
 
117  3420 toggle public Method getMethod() {
118  3420 return invocation.getMethod();
119    }
120    }