Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
30   125   20   7,5
24   53   0,67   4
4     5  
1    
 
 
  AbstractMatcher       Line # 19 30 20 100% 1.0
 
  (56)
 
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;
6   
7    import java.io.Serializable;
8   
9    /**
10    * A convenience implementation of {@link ArgumentsMatcher}. A subclass that
11    * does not redefine any method will behave like
12    * {@link MockControl#EQUALS_MATCHER}.
13    *
14    * @deprecated Since EasyMock 2.0, <code>ArgumentsMatcher</code>s are only supported
15    * for the legacy <code>MockControl</code>. For mock objects generated by the methods
16    * on <code>EasyMock</code>, there are per-argument matchers available. For more
17    * information, see the EasyMock documentation.
18    */
 
19    public abstract class AbstractMatcher implements ArgumentsMatcher, Serializable {
20   
21    private static final long serialVersionUID = -5463061331694985383L;
22   
23    /**
24    * Checks whether an expected argument matches an actual argument; the method
25    * is used by
26    * {@link AbstractMatcher#matches(Object[], Object[])}. The arguments
27    * provided to this method are always not <code>null</code>.
28    *
29    * @param expected
30    * the expected argument.
31    * @param actual
32    * the actual argument.
33    * @return true if the arguments match, false otherwise.
34    */
 
35  1 toggle protected boolean argumentMatches(Object expected, Object actual) {
36  1 return expected.equals(actual);
37    }
38   
39    /**
40    * Converts an argument to a String, used by
41    * {@link AbstractMatcher#toString(Object[])}.
42    *
43    * @param argument
44    * the argument to convert to a String.
45    * @return a <code>String</code> representation of the argument.
46    */
 
47  61 toggle protected String argumentToString(Object argument) {
48  61 if (argument instanceof String) {
49  27 return "\"" + argument + "\"";
50    }
51  34 return "" + argument;
52    }
53   
54    /**
55    * Checks whether an expected argument array matches an actual argument array.
56    * This convenience implementation uses
57    * <code>argumentMatches(Object, Object)</code> to check whether arguments
58    * pairs match. If all the arguments match, true is returned, otherwise
59    * false. In two cases, <code>argumentMatches(Object, Object)</code> is
60    * not called: If both argument arrays are null, they match; if one and only
61    * one is null, they do not match.
62    *
63    * @param expected
64    * the expected arguments.
65    * @param actual
66    * the actual arguments.
67    * @return true if the arguments match, false otherwise.
68    */
 
69  38 toggle public boolean matches(Object[] expected, Object[] actual) {
70  38 if (expected == actual) {
71  1 return true;
72    }
73  37 if (expected == null || actual == null) {
74  2 return false;
75    }
76  35 if (expected.length != actual.length) {
77  1 return false;
78    }
79  49 for (int i = 0; i < expected.length; i++) {
80  33 Object expectedObject = expected[i];
81  33 Object actualObject = actual[i];
82   
83  33 if (expectedObject == null && actualObject == null) {
84  1 continue;
85    }
86   
87  32 if (expectedObject == null && actualObject != null) {
88  2 return false;
89    }
90   
91  30 if (expectedObject != null && actualObject == null) {
92  2 return false;
93    }
94   
95  28 if (!argumentMatches(expectedObject, actualObject)) {
96  14 return false;
97    }
98    }
99  16 return true;
100    }
101   
102    /**
103    * Returns a string representation of the matcher. This convenience
104    * implementation calls {@link AbstractMatcher#argumentToString(Object)}
105    * for every argument in the given array and returns the string representations
106    * of the arguments separated by commas.
107    *
108    * @param arguments
109    * the arguments to be used in the string representation.
110    * @return a string representation of the matcher.
111    */
 
112  73 toggle public String toString(Object[] arguments) {
113  73 if (arguments == null)
114  1 arguments = new Object[0];
115   
116  73 StringBuffer result = new StringBuffer();
117   
118  150 for (int i = 0; i < arguments.length; i++) {
119  78 if (i > 0)
120  16 result.append(", ");
121  78 result.append(argumentToString(arguments[i]));
122    }
123  72 return result.toString();
124    }
125    }