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: | 79 |  | Methods: | 5
| NCLOC: | 68 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

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