1 package org.testng.internal.junit; 2 3 public class ArrayAsserts { 4 /** 5 * Asserts that two object arrays are equal. If they are not, an 6 * {@link AssertionError} is thrown with the given message. If 7 * <code>expecteds</code> and <code>actuals</code> are <code>null</code>, 8 * they are considered equal. 9 * 10 * @param message 11 * the identifying message for the {@link AssertionError} (<code>null</code> 12 * okay) 13 * @param expecteds 14 * Object array or array of arrays (multi-dimensional array) with 15 * expected values. 16 * @param actuals 17 * Object array or array of arrays (multi-dimensional array) with 18 * actual values 19 */ assertArrayEquals(String message, Object[] expecteds, Object[] actuals)20 public static void assertArrayEquals(String message, Object[] expecteds, 21 Object[] actuals) throws ArrayComparisonFailure { 22 internalArrayEquals(message, expecteds, actuals); 23 } 24 25 /** 26 * Asserts that two object arrays are equal. If they are not, an 27 * {@link AssertionError} is thrown. If <code>expected</code> and 28 * <code>actual</code> are <code>null</code>, they are considered 29 * equal. 30 * 31 * @param expecteds 32 * Object array or array of arrays (multi-dimensional array) with 33 * expected values 34 * @param actuals 35 * Object array or array of arrays (multi-dimensional array) with 36 * actual values 37 */ assertArrayEquals(Object[] expecteds, Object[] actuals)38 public static void assertArrayEquals(Object[] expecteds, Object[] actuals) { 39 assertArrayEquals(null, expecteds, actuals); 40 } 41 42 /** 43 * Asserts that two byte arrays are equal. If they are not, an 44 * {@link AssertionError} is thrown with the given message. 45 * 46 * @param message 47 * the identifying message for the {@link AssertionError} (<code>null</code> 48 * okay) 49 * @param expecteds 50 * byte array with expected values. 51 * @param actuals 52 * byte array with actual values 53 */ assertArrayEquals(String message, byte[] expecteds, byte[] actuals)54 public static void assertArrayEquals(String message, byte[] expecteds, 55 byte[] actuals) throws ArrayComparisonFailure { 56 internalArrayEquals(message, expecteds, actuals); 57 } 58 59 /** 60 * Asserts that two byte arrays are equal. If they are not, an 61 * {@link AssertionError} is thrown. 62 * 63 * @param expecteds 64 * byte array with expected values. 65 * @param actuals 66 * byte array with actual values 67 */ assertArrayEquals(byte[] expecteds, byte[] actuals)68 public static void assertArrayEquals(byte[] expecteds, byte[] actuals) { 69 assertArrayEquals(null, expecteds, actuals); 70 } 71 72 /** 73 * Asserts that two char arrays are equal. If they are not, an 74 * {@link AssertionError} is thrown with the given message. 75 * 76 * @param message 77 * the identifying message for the {@link AssertionError} (<code>null</code> 78 * okay) 79 * @param expecteds 80 * char array with expected values. 81 * @param actuals 82 * char array with actual values 83 */ assertArrayEquals(String message, char[] expecteds, char[] actuals)84 public static void assertArrayEquals(String message, char[] expecteds, 85 char[] actuals) throws ArrayComparisonFailure { 86 internalArrayEquals(message, expecteds, actuals); 87 } 88 89 /** 90 * Asserts that two char arrays are equal. If they are not, an 91 * {@link AssertionError} is thrown. 92 * 93 * @param expecteds 94 * char array with expected values. 95 * @param actuals 96 * char array with actual values 97 */ assertArrayEquals(char[] expecteds, char[] actuals)98 public static void assertArrayEquals(char[] expecteds, char[] actuals) { 99 assertArrayEquals(null, expecteds, actuals); 100 } 101 102 /** 103 * Asserts that two short arrays are equal. If they are not, an 104 * {@link AssertionError} is thrown with the given message. 105 * 106 * @param message 107 * the identifying message for the {@link AssertionError} (<code>null</code> 108 * okay) 109 * @param expecteds 110 * short array with expected values. 111 * @param actuals 112 * short array with actual values 113 */ assertArrayEquals(String message, short[] expecteds, short[] actuals)114 public static void assertArrayEquals(String message, short[] expecteds, 115 short[] actuals) throws ArrayComparisonFailure { 116 internalArrayEquals(message, expecteds, actuals); 117 } 118 119 /** 120 * Asserts that two short arrays are equal. If they are not, an 121 * {@link AssertionError} is thrown. 122 * 123 * @param expecteds 124 * short array with expected values. 125 * @param actuals 126 * short array with actual values 127 */ assertArrayEquals(short[] expecteds, short[] actuals)128 public static void assertArrayEquals(short[] expecteds, short[] actuals) { 129 assertArrayEquals(null, expecteds, actuals); 130 } 131 132 /** 133 * Asserts that two int arrays are equal. If they are not, an 134 * {@link AssertionError} is thrown with the given message. 135 * 136 * @param message 137 * the identifying message for the {@link AssertionError} (<code>null</code> 138 * okay) 139 * @param expecteds 140 * int array with expected values. 141 * @param actuals 142 * int array with actual values 143 */ assertArrayEquals(String message, int[] expecteds, int[] actuals)144 public static void assertArrayEquals(String message, int[] expecteds, 145 int[] actuals) throws ArrayComparisonFailure { 146 internalArrayEquals(message, expecteds, actuals); 147 } 148 149 /** 150 * Asserts that two int arrays are equal. If they are not, an 151 * {@link AssertionError} is thrown. 152 * 153 * @param expecteds 154 * int array with expected values. 155 * @param actuals 156 * int array with actual values 157 */ assertArrayEquals(int[] expecteds, int[] actuals)158 public static void assertArrayEquals(int[] expecteds, int[] actuals) { 159 assertArrayEquals(null, expecteds, actuals); 160 } 161 162 /** 163 * Asserts that two long arrays are equal. If they are not, an 164 * {@link AssertionError} is thrown with the given message. 165 * 166 * @param message 167 * the identifying message for the {@link AssertionError} (<code>null</code> 168 * okay) 169 * @param expecteds 170 * long array with expected values. 171 * @param actuals 172 * long array with actual values 173 */ assertArrayEquals(String message, long[] expecteds, long[] actuals)174 public static void assertArrayEquals(String message, long[] expecteds, 175 long[] actuals) throws ArrayComparisonFailure { 176 internalArrayEquals(message, expecteds, actuals); 177 } 178 179 /** 180 * Asserts that two long arrays are equal. If they are not, an 181 * {@link AssertionError} is thrown. 182 * 183 * @param expecteds 184 * long array with expected values. 185 * @param actuals 186 * long array with actual values 187 */ assertArrayEquals(long[] expecteds, long[] actuals)188 public static void assertArrayEquals(long[] expecteds, long[] actuals) { 189 assertArrayEquals(null, expecteds, actuals); 190 } 191 192 /** 193 * Asserts that two double arrays are equal. If they are not, an 194 * {@link AssertionError} is thrown with the given message. 195 * 196 * @param message 197 * the identifying message for the {@link AssertionError} (<code>null</code> 198 * okay) 199 * @param expecteds 200 * double array with expected values. 201 * @param actuals 202 * double array with actual values 203 */ assertArrayEquals(String message, double[] expecteds, double[] actuals, double delta)204 public static void assertArrayEquals(String message, double[] expecteds, 205 double[] actuals, double delta) throws ArrayComparisonFailure { 206 new InexactComparisonCriteria(delta).arrayEquals(message, expecteds, actuals); 207 } 208 209 /** 210 * Asserts that two double arrays are equal. If they are not, an 211 * {@link AssertionError} is thrown. 212 * 213 * @param expecteds 214 * double array with expected values. 215 * @param actuals 216 * double array with actual values 217 */ assertArrayEquals(double[] expecteds, double[] actuals, double delta)218 public static void assertArrayEquals(double[] expecteds, double[] actuals, double delta) { 219 assertArrayEquals(null, expecteds, actuals, delta); 220 } 221 222 /** 223 * Asserts that two float arrays are equal. If they are not, an 224 * {@link AssertionError} is thrown with the given message. 225 * 226 * @param message 227 * the identifying message for the {@link AssertionError} (<code>null</code> 228 * okay) 229 * @param expecteds 230 * float array with expected values. 231 * @param actuals 232 * float array with actual values 233 */ assertArrayEquals(String message, float[] expecteds, float[] actuals, float delta)234 public static void assertArrayEquals(String message, float[] expecteds, 235 float[] actuals, float delta) throws ArrayComparisonFailure { 236 new InexactComparisonCriteria(delta).arrayEquals(message, expecteds, actuals); 237 } 238 239 /** 240 * Asserts that two float arrays are equal. If they are not, an 241 * {@link AssertionError} is thrown. 242 * 243 * @param expecteds 244 * float array with expected values. 245 * @param actuals 246 * float array with actual values 247 */ assertArrayEquals(float[] expecteds, float[] actuals, float delta)248 public static void assertArrayEquals(float[] expecteds, float[] actuals, float delta) { 249 assertArrayEquals(null, expecteds, actuals, delta); 250 } 251 252 /** 253 * Asserts that two object arrays are equal. If they are not, an 254 * {@link AssertionError} is thrown with the given message. If 255 * <code>expecteds</code> and <code>actuals</code> are <code>null</code>, 256 * they are considered equal. 257 * 258 * @param message 259 * the identifying message for the {@link AssertionError} (<code>null</code> 260 * okay) 261 * @param expecteds 262 * Object array or array of arrays (multi-dimensional array) with 263 * expected values. 264 * @param actuals 265 * Object array or array of arrays (multi-dimensional array) with 266 * actual values 267 */ internalArrayEquals(String message, Object expecteds, Object actuals)268 private static void internalArrayEquals(String message, Object expecteds, 269 Object actuals) throws ArrayComparisonFailure { 270 new ExactComparisonCriteria().arrayEquals(message, expecteds, actuals); 271 } 272 273 } 274