Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
37   122   21   3,36
22   99   0,57   11
11     1,91  
1    
 
 
  ExpectedInvocation       Line # 16 37 21 100% 1.0
 
  (245)
 
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.lang.reflect.Method;
9    import java.util.ArrayList;
10    import java.util.Iterator;
11    import java.util.List;
12   
13    import org.easymock.IArgumentMatcher;
14    import org.easymock.internal.matchers.Equals;
15   
 
16    public class ExpectedInvocation implements Serializable {
17   
18    private static final long serialVersionUID = -5554816464613350531L;
19   
20    private final Invocation invocation;
21   
22    @SuppressWarnings("deprecation")
23    private final org.easymock.ArgumentsMatcher matcher;
24   
25    private final List<IArgumentMatcher> matchers;
26   
 
27  492 toggle public ExpectedInvocation(Invocation invocation,
28    List<IArgumentMatcher> matchers) {
29  492 this(invocation, matchers, null);
30    }
31   
 
32  531 toggle private ExpectedInvocation(Invocation invocation,
33    List<IArgumentMatcher> matchers, @SuppressWarnings("deprecation")
34    org.easymock.ArgumentsMatcher matcher) {
35  531 this.invocation = invocation;
36  531 this.matcher = matcher;
37  531 this.matchers = (matcher == null) ? createMissingMatchers(invocation,
38    matchers) : null;
39    }
40   
 
41  493 toggle private List<IArgumentMatcher> createMissingMatchers(Invocation invocation,
42    List<IArgumentMatcher> matchers) {
43  493 if (matchers != null) {
44  137 if (matchers.size() != invocation.getArguments().length) {
45  1 throw new IllegalStateException(""
46    + invocation.getArguments().length
47    + " matchers expected, " + matchers.size()
48    + " recorded.");
49    }
50  136 ;
51  136 return matchers;
52    }
53  356 List<IArgumentMatcher> result = new ArrayList<IArgumentMatcher>();
54  356 for (Object argument : invocation.getArguments()) {
55  376 result.add(new Equals(argument));
56    }
57  356 return result;
58    }
59   
 
60  683 toggle public boolean equals(Object o) {
61  683 if (o == null || !this.getClass().equals(o.getClass()))
62  1 return false;
63   
64  682 ExpectedInvocation other = (ExpectedInvocation) o;
65  682 return this.invocation.equals(other.invocation)
66    && ((this.matcher == null && other.matcher == null) || (this.matcher != null && this.matcher
67    .equals(other.matcher)))
68    && ((this.matchers == null && other.matchers == null) || (this.matchers != null && this.matchers
69    .equals(other.matchers)));
70    }
71   
 
72  1 toggle public int hashCode() {
73  1 return invocation.hashCode();
74    }
75   
 
76  1712 toggle public boolean matches(Invocation actual) {
77  1712 return matchers != null ? this.invocation.getMock().equals(
78    actual.getMock())
79    && this.invocation.getMethod().equals(actual.getMethod())
80    && matches(actual.getArguments()) : this.invocation.matches(
81    actual, matcher);
82    }
83   
 
84  885 toggle private boolean matches(Object[] arguments) {
85  885 if (arguments.length != matchers.size()) {
86  20 return false;
87    }
88  1507 for (int i = 0; i < arguments.length; i++) {
89  937 if (!matchers.get(i).matches(arguments[i])) {
90  295 return false;
91    }
92    }
93  570 return true;
94    }
95   
 
96  244 toggle public String toString() {
97  244 return matchers != null ? myToString() : invocation.toString(matcher);
98    }
99   
 
100  234 toggle private String myToString() {
101  234 StringBuffer result = new StringBuffer();
102  234 result.append(invocation.getMockAndMethodName());
103  234 result.append("(");
104  485 for (Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
105  254 it.next().appendTo(result);
106  251 if (it.hasNext()) {
107  51 result.append(", ");
108    }
109    }
110  231 result.append(")");
111  231 return result.toString();
112    }
113   
 
114  1265 toggle public Method getMethod() {
115  1265 return invocation.getMethod();
116    }
117   
 
118  38 toggle public ExpectedInvocation withMatcher(@SuppressWarnings("deprecation")
119    org.easymock.ArgumentsMatcher matcher) {
120  38 return new ExpectedInvocation(invocation, null, matcher);
121    }
122    }