Clover Coverage Report - EasyMock 2.4
Coverage timestamp: mer. juil. 2 2008 02:17:38 CEST
36   81   38   7,2
28   69   1,06   5
5     7,6  
1    
 
 
  ArrayEquals       Line # 10 36 38 100% 1.0
 
  (27)
 
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.matchers;
6   
7    import java.lang.reflect.Array;
8    import java.util.Arrays;
9   
 
10    public class ArrayEquals extends Equals {
11   
12    private static final long serialVersionUID = 1L;
13   
 
14  54 toggle public ArrayEquals(Object expected) {
15  54 super(expected);
16    }
17   
 
18  39 toggle public boolean matches(Object actual) {
19  39 Object expected = getExpected();
20  39 if (expected instanceof boolean[]
21    && (actual == null || actual instanceof boolean[])) {
22  3 return Arrays.equals((boolean[]) expected, (boolean[]) actual);
23  36 } else if (expected instanceof byte[]
24    && (actual == null || actual instanceof byte[])) {
25  3 return Arrays.equals((byte[]) expected, (byte[]) actual);
26  33 } else if (expected instanceof char[]
27    && (actual == null || actual instanceof char[])) {
28  3 return Arrays.equals((char[]) expected, (char[]) actual);
29  30 } else if (expected instanceof double[]
30    && (actual == null || actual instanceof double[])) {
31  3 return Arrays.equals((double[]) expected, (double[]) actual);
32  27 } else if (expected instanceof float[]
33    && (actual == null || actual instanceof float[])) {
34  3 return Arrays.equals((float[]) expected, (float[]) actual);
35  24 } else if (expected instanceof int[]
36    && (actual == null || actual instanceof int[])) {
37  8 return Arrays.equals((int[]) expected, (int[]) actual);
38  16 } else if (expected instanceof long[]
39    && (actual == null || actual instanceof long[])) {
40  3 return Arrays.equals((long[]) expected, (long[]) actual);
41  13 } else if (expected instanceof short[]
42    && (actual == null || actual instanceof short[])) {
43  3 return Arrays.equals((short[]) expected, (short[]) actual);
44  10 } else if (expected instanceof Object[]
45    && (actual == null || actual instanceof Object[])) {
46  8 return Arrays.equals((Object[]) expected, (Object[]) actual);
47    } else {
48  2 return super.matches(actual);
49    }
50    }
51   
 
52  15 toggle public void appendTo(StringBuffer buffer) {
53  15 if (getExpected() != null && getExpected().getClass().isArray()) {
54  13 appendArray(createObjectArray(getExpected()), buffer);
55    } else {
56  2 super.appendTo(buffer);
57    }
58    }
59   
 
60  13 toggle private void appendArray(Object[] array, StringBuffer buffer) {
61  13 buffer.append("[");
62  39 for (int i = 0; i < array.length; i++) {
63  26 new Equals(array[i]).appendTo(buffer);
64  26 if (i != array.length - 1) {
65  13 buffer.append(", ");
66    }
67    }
68  13 buffer.append("]");
69    }
70   
 
71  55 toggle public static Object[] createObjectArray(Object array) {
72  55 if (array instanceof Object[]) {
73  14 return (Object[]) array;
74    }
75  41 Object[] result = new Object[Array.getLength(array)];
76  107 for (int i = 0; i < Array.getLength(array); i++) {
77  66 result[i] = Array.get(array, i);
78    }
79  41 return result;
80    }
81    }