1 | /* |
2 | * JTiger Unit Testing Framework for J2SE 1.5 |
3 | * Copyright (C) 2005 Tony Morris |
4 | * |
5 | * This software is licenced under the |
6 | * Common Public Licence version 1.0 |
7 | * http://www.opensource.org/licenses/cpl1.0.php |
8 | * |
9 | * You received a copy of this licence with this software. |
10 | */ |
11 | package org.jtiger.assertion; |
12 | |
13 | import static org.jtiger.assertion.BoxedTypePromoterFactory.newBoxedTypePromoter; |
14 | import java.util.Arrays; |
15 | |
16 | /** |
17 | * Provides the ability to make assertions that are of the most basic and trivial concepts. |
18 | * |
19 | * @author %javadoc.author.tag% |
20 | * @version %version%<br/> |
21 | * <i>Build Number %build.number%</i><br/> |
22 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
23 | */ |
24 | public final class Basic |
25 | { |
26 | private Basic() |
27 | { |
28 | /*throw new UnsupportedOperationException( |
29 | "class Basic is not instantiable");*/ |
30 | } |
31 | |
32 | /** |
33 | * Asserts that the given <code>boolean</code> argument is <code>true</code>. |
34 | * |
35 | * @param b The argument to assert is <code>true</code>. |
36 | * @param message The assertion message. |
37 | * @throws AssertionException If the given <code>boolean</code> argument is not <code>true</code>. |
38 | */ |
39 | public static void assertTrue(final boolean b, final Object... message) throws AssertionException |
40 | { |
41 | if(!b) |
42 | { |
43 | throw new AssertionException(message); |
44 | } |
45 | } |
46 | |
47 | /** |
48 | * Asserts that the given <code>boolean</code> argument is <code>true</code>. |
49 | * |
50 | * @param b The argument to assert is <code>true</code>. |
51 | * @param message The assertion message. |
52 | * @throws AssertionException If the given <code>boolean</code> argument is not <code>true</code>. |
53 | */ |
54 | public static void assertFalse(final boolean b, final Object... message) throws AssertionException |
55 | { |
56 | if(b) |
57 | { |
58 | throw new AssertionException(message); |
59 | } |
60 | } |
61 | |
62 | /** |
63 | * Asserts that the given <code>Object</code> argument is <code>null</code>. |
64 | * |
65 | * @param o The argument to assert is <code>null</code>. |
66 | * @param message The assertion message. |
67 | * @throws AssertionException If the given <code>Object</code> argument is not <code>null</code>. |
68 | */ |
69 | public static void assertNull(final Object o, final Object... message) throws AssertionException |
70 | { |
71 | if(o != null) |
72 | { |
73 | throw new AssertionException(message); |
74 | } |
75 | } |
76 | |
77 | /** |
78 | * Asserts that the given <code>Object</code> argument is not <code>null</code>. |
79 | * |
80 | * @param o The argument to assert is not <code>null</code>. |
81 | * @param message The assertion message. |
82 | * @throws AssertionException If the given <code>Object</code> argument is <code>null</code>. |
83 | */ |
84 | public static void assertNotNull(final Object o, final Object... message) throws AssertionException |
85 | { |
86 | if(o == null) |
87 | { |
88 | throw new AssertionException(message); |
89 | } |
90 | } |
91 | |
92 | /** |
93 | * Asserts that the given expected <code>Object</code> argument is equal to the actual <code>Object</code> argument. |
94 | * Equality of two references is determined by both referring to <code>null</code> or being equal according to the |
95 | * semantics of |
96 | * <a href="%j2se.api.spec%/java/lang/Object.html#equals(java.lang.Object)">the java.lang.Object equals method</a>. |
97 | * <br/> |
98 | * <code>expected == null && actual == null || (expected != null && expected.equals(actual))</code><br/> |
99 | * If either the <code>expected</code> or <code>actual</code> argument is of type <tt>Byte</tt>, <tt>Short</tt>, |
100 | * <tt>Character</tt>, or <tt>Integer</tt>, it is explicitly promoted to type <tt>Long</tt>. If either argument is |
101 | * of type <tt>Float</tt>, it is promoted to type <tt>Double</tt>. This is so that the boxed type will be equal if |
102 | * it has the same value, even though it is of a different type. For example, <code>assertEqual(7, 7L)</code> will |
103 | * autobox each argument to type <tt>Integer</tt> and <tt>Long</tt> respectively, an since |
104 | * <code>new Integer(7).equals(new Long(7L))</code> will be <code>false</code>, the assertion would fail, therefore, |
105 | * the first argument is promoted to type <tt>Long</tt> first, so that the test for equality will succeed. |
106 | * |
107 | * @param expected The expected value to test for equality. |
108 | * @param actual The actual value to test for equality. |
109 | * @param message The assertion message. |
110 | * @throws AssertionException If the given expected <code>Object</code> argument is not equal to the actual |
111 | * <code>Object</code> argument. |
112 | */ |
113 | public static void assertEqual(final Object expected, final Object actual, final Object... message) throws AssertionException |
114 | { |
115 | final BoxedTypePromoter btp = newBoxedTypePromoter(); |
116 | |
117 | final Object promotedExpected = btp.promote(expected); |
118 | final Object promotedActual = btp.promote(actual); |
119 | |
120 | if(!(promotedExpected == null && promotedActual == null || (promotedExpected != null && promotedExpected.equals(promotedActual)))) |
121 | { |
122 | throw new AssertionException(message); |
123 | } |
124 | } |
125 | |
126 | /** |
127 | * Asserts that the given expected <code>Object</code> array argument is equal to the actual <code>Object</code> |
128 | * array argument. |
129 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
130 | * to the semantics of |
131 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(java.lang.Object[], java.lang.Object[])">java.util.Arrays equals(Object[], Object[]) method</a> |
132 | * <br/> |
133 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
134 | * |
135 | * @param expected The expected value to test for equality. |
136 | * @param actual The actual value to test for equality. |
137 | * @param message The assertion message. |
138 | * @throws AssertionException If the given expected <code>Object</code> array argument is not equal to the actual |
139 | * <code>Object</code> array argument. |
140 | */ |
141 | public static void assertEqual(final Object[] expected, final Object[] actual, final Object... message) throws AssertionException |
142 | { |
143 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
144 | { |
145 | throw new AssertionException(message); |
146 | } |
147 | } |
148 | |
149 | /** |
150 | * Asserts that the given expected <code>double</code> array argument is equal to the actual <code>double</code> |
151 | * array argument. |
152 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
153 | * to the semantics of |
154 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(double[], double[])">the java.util.Arrays equals(double[], double[]) method</a>. |
155 | * <br/> |
156 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
157 | * |
158 | * @param expected The expected value to test for equality. |
159 | * @param actual The actual value to test for equality. |
160 | * @param message The assertion message. |
161 | * @throws AssertionException If the given expected <code>double</code> array argument is not equal to the actual |
162 | * <code>double</code> array argument. |
163 | */ |
164 | public static void assertEqual(final double[] expected, final double[] actual, final Object... message) throws AssertionException |
165 | { |
166 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
167 | { |
168 | throw new AssertionException(message); |
169 | } |
170 | } |
171 | |
172 | /** |
173 | * Asserts that the given expected <code>float</code> array argument is equal to the actual <code>float</code> |
174 | * array argument. |
175 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
176 | * to the semantics of |
177 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(float[], float[])">the java.util.Arrays equals(float[], float[]) method</a>. |
178 | * <br/> |
179 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
180 | * |
181 | * @param expected The expected value to test for equality. |
182 | * @param actual The actual value to test for equality. |
183 | * @param message The assertion message. |
184 | * @throws AssertionException If the given expected <code>float</code> array argument is not equal to the actual |
185 | * <code>float</code> array argument. |
186 | */ |
187 | public static void assertEqual(final float[] expected, final float[] actual, final Object... message) throws AssertionException |
188 | { |
189 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
190 | { |
191 | throw new AssertionException(message); |
192 | } |
193 | } |
194 | |
195 | /** |
196 | * Asserts that the given expected <code>boolean</code> array argument is equal to the actual <code>boolean</code> |
197 | * array argument. |
198 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
199 | * to the semantics of |
200 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(boolean[], boolean[])">the java.util.Arrays equals(boolean[], boolean[]) method</a>. |
201 | * <br/> |
202 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
203 | * |
204 | * @param expected The expected value to test for equality. |
205 | * @param actual The actual value to test for equality. |
206 | * @param message The assertion message. |
207 | * @throws AssertionException If the given expected <code>boolean</code> array argument is not equal to the actual |
208 | * <code>boolean</code> array argument. |
209 | */ |
210 | public static void assertEqual(final boolean[] expected, final boolean[] actual, final Object... message) throws AssertionException |
211 | { |
212 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
213 | { |
214 | throw new AssertionException(message); |
215 | } |
216 | } |
217 | |
218 | /** |
219 | * Asserts that the given expected <code>byte</code> array argument is equal to the actual <code>byte</code> |
220 | * array argument. |
221 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
222 | * to the semantics of |
223 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(byte[], byte[])">the java.util.Arrays equals(byte[], byte[]) method</a>. |
224 | * <br/> |
225 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
226 | * |
227 | * @param expected The expected value to test for equality. |
228 | * @param actual The actual value to test for equality. |
229 | * @param message The assertion message. |
230 | * @throws AssertionException If the given expected <code>byte</code> array argument is not equal to the actual |
231 | * <code>byte</code> array argument. |
232 | */ |
233 | public static void assertEqual(final byte[] expected, final byte[] actual, final Object... message) throws AssertionException |
234 | { |
235 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
236 | { |
237 | throw new AssertionException(message); |
238 | } |
239 | } |
240 | |
241 | /** |
242 | * Asserts that the given expected <code>short</code> array argument is equal to the actual <code>short</code> |
243 | * array argument. |
244 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
245 | * to the semantics of |
246 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(short[], short[])">the java.util.Arrays equals(short[], short[]) method</a>. |
247 | * <br/> |
248 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
249 | * |
250 | * @param expected The expected value to test for equality. |
251 | * @param actual The actual value to test for equality. |
252 | * @param message The assertion message. |
253 | * @throws AssertionException If the given expected <code>short</code> array argument is not equal to the actual |
254 | * <code>short</code> array argument. |
255 | */ |
256 | public static void assertEqual(final short[] expected, final short[] actual, final Object... message) throws AssertionException |
257 | { |
258 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
259 | { |
260 | throw new AssertionException(message); |
261 | } |
262 | } |
263 | |
264 | /** |
265 | * Asserts that the given expected <code>char</code> array argument is equal to the actual <code>char</code> |
266 | * array argument. |
267 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
268 | * to the semantics of |
269 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(char[], char[])">the java.util.Arrays equals(char[], char[]) method</a>. |
270 | * <br/> |
271 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
272 | * |
273 | * @param expected The expected value to test for equality. |
274 | * @param actual The actual value to test for equality. |
275 | * @param message The assertion message. |
276 | * @throws AssertionException If the given expected <code>char</code> array argument is not equal to the actual |
277 | * <code>char</code> array argument. |
278 | */ |
279 | public static void assertEqual(final char[] expected, final char[] actual, final Object... message) throws AssertionException |
280 | { |
281 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
282 | { |
283 | throw new AssertionException(message); |
284 | } |
285 | } |
286 | |
287 | /** |
288 | * Asserts that the given expected <code>int</code> array argument is equal to the actual <code>int</code> |
289 | * array argument. |
290 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
291 | * to the semantics of |
292 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(int[], int[])">the java.util.Arrays equals(int[], int[]) method</a>. |
293 | * <br/> |
294 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
295 | * |
296 | * @param expected The expected value to test for equality. |
297 | * @param actual The actual value to test for equality. |
298 | * @param message The assertion message. |
299 | * @throws AssertionException If the given expected <code>int</code> array argument is not equal to the actual |
300 | * <code>int</code> array argument. |
301 | */ |
302 | public static void assertEqual(final int[] expected, final int[] actual, final Object... message) throws AssertionException |
303 | { |
304 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
305 | { |
306 | throw new AssertionException(message); |
307 | } |
308 | } |
309 | |
310 | /** |
311 | * Asserts that the given expected <code>long</code> array argument is equal to the actual <code>long</code> |
312 | * array argument. |
313 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
314 | * to the semantics of |
315 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(long[], long[])">the java.util.Arrays equals(long[], long[]) method</a>. |
316 | * <br/> |
317 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
318 | * |
319 | * @param expected The expected value to test for equality. |
320 | * @param actual The actual value to test for equality. |
321 | * @param message The assertion message. |
322 | * @throws AssertionException If the given expected <code>long</code> array argument is not equal to the actual |
323 | * <code>long</code> array argument. |
324 | */ |
325 | public static void assertEqual(final long[] expected, final long[] actual, final Object... message) throws AssertionException |
326 | { |
327 | if(!(expected == null && actual == null || (Arrays.equals(expected, actual)))) |
328 | { |
329 | throw new AssertionException(message); |
330 | } |
331 | } |
332 | |
333 | /** |
334 | * Asserts that the given expected <code>Object</code> argument is not equal to the actual |
335 | * <code>Object</code> argument. |
336 | * Equality of two references is determined by both referring to <code>null</code> or being equal according to the |
337 | * semantics of |
338 | * <a href="%j2se.api.spec%/java/lang/Object.html#equals(java.lang.Object)">the java.lang.Object equals method</a>. |
339 | * <br/> |
340 | * <code>!(expected == null && actual == null || (expected != null && expected.equals(actual)))</code> |
341 | * If either the <code>expected</code> or <code>actual</code> argument is of type <tt>Byte</tt>, <tt>Short</tt>, |
342 | * <tt>Character</tt>, or <tt>Integer</tt>, it is explicitly promoted to type <tt>Long</tt>. If either argument is |
343 | * of type <tt>Float</tt>, it is promoted to type <tt>Double</tt>. This is so that the boxed type will be equal if |
344 | * it has the same value, even though it is of a different type. For example, <code>assertEqual(7, 7L)</code> will |
345 | * autobox each argument to type <tt>Integer</tt> and <tt>Long</tt> respectively, an since |
346 | * <code>new Integer(7).equals(new Long(7L))</code> will be <code>false</code>, the assertion would fail, therefore, |
347 | * the first argument is promoted to type <tt>Long</tt> first, so that the test for equality will succeed. |
348 | * |
349 | * @param expected The expected value to test for inequality. |
350 | * @param actual The actual value to test for inequality. |
351 | * @param message The assertion message. |
352 | * @throws AssertionException If the given expected <code>Object</code> argument is equal to the actual |
353 | * <code>Object</code> argument. |
354 | */ |
355 | public static void assertNotEqual(final Object expected, final Object actual, final Object... message) throws AssertionException |
356 | { |
357 | final BoxedTypePromoter btp = newBoxedTypePromoter(); |
358 | |
359 | final Object promotedExpected = btp.promote(expected); |
360 | final Object promotedActual = btp.promote(actual); |
361 | |
362 | if(promotedExpected == null && promotedActual == null || (promotedExpected != null && promotedExpected.equals(promotedActual))) |
363 | { |
364 | throw new AssertionException(message); |
365 | } |
366 | } |
367 | |
368 | /** |
369 | * Asserts that the given expected <code>Object</code> array argument is not equal to the actual <code>Object</code> |
370 | * array argument. |
371 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
372 | * to the semantics of |
373 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(java.lang.Object[], java.lang.Object[])">the java.util.Arrays equals(Object[], Object[]) method</a>. |
374 | * <br/> |
375 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
376 | * |
377 | * @param expected The expected value to test for inequality. |
378 | * @param actual The actual value to test for inequality. |
379 | * @param message The assertion message. |
380 | * @throws AssertionException If the given expected <code>Object</code> array argument is equal to the actual |
381 | * <code>Object</code> array argument. |
382 | */ |
383 | public static void assertNotEqual(final Object[] expected, final Object[] actual, final Object... message) throws AssertionException |
384 | { |
385 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
386 | { |
387 | throw new AssertionException(message); |
388 | } |
389 | } |
390 | |
391 | /** |
392 | * Asserts that the given expected <code>double</code> array argument is not equal to the actual <code>double</code> |
393 | * array argument. |
394 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
395 | * to the semantics of |
396 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(double[], double[])">the java.util.Arrays equals(double[], double[]) method</a>. |
397 | * <br/> |
398 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
399 | * |
400 | * @param expected The expected value to test for inequality. |
401 | * @param actual The actual value to test for inequality. |
402 | * @param message The assertion message. |
403 | * @throws AssertionException If the given expected <code>double</code> array argument is equal to the actual |
404 | * <code>double</code> array argument. |
405 | */ |
406 | public static void assertNotEqual(final double[] expected, final double[] actual, final Object... message) throws AssertionException |
407 | { |
408 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
409 | { |
410 | throw new AssertionException(message); |
411 | } |
412 | } |
413 | |
414 | /** |
415 | * Asserts that the given expected <code>float</code> array argument is not equal to the actual <code>float</code> |
416 | * array argument. |
417 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
418 | * to the semantics of |
419 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(float[], float[])">the java.util.Arrays equals(float[], float[]) method</a>. |
420 | * <br/> |
421 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
422 | * |
423 | * @param expected The expected value to test for inequality. |
424 | * @param actual The actual value to test for inequality. |
425 | * @param message The assertion message. |
426 | * @throws AssertionException If the given expected <code>float</code> array argument is equal to the actual |
427 | * <code>float</code> array argument. |
428 | */ |
429 | public static void assertNotEqual(final float[] expected, final float[] actual, final Object... message) throws AssertionException |
430 | { |
431 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
432 | { |
433 | throw new AssertionException(message); |
434 | } |
435 | } |
436 | |
437 | /** |
438 | * Asserts that the given expected <code>boolean</code> array argument is not equal to the actual <code>boolean</code> |
439 | * array argument. |
440 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
441 | * to the semantics of |
442 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(boolean[], boolean[])">the java.util.Arrays equals(boolean[], boolean[]) method</a>. |
443 | * <br/> |
444 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
445 | * |
446 | * @param expected The expected value to test for inequality. |
447 | * @param actual The actual value to test for inequality. |
448 | * @param message The assertion message. |
449 | * @throws AssertionException If the given expected <code>boolean</code> array argument is equal to the actual |
450 | * <code>boolean</code> array argument. |
451 | */ |
452 | public static void assertNotEqual(final boolean[] expected, final boolean[] actual, final Object... message) throws AssertionException |
453 | { |
454 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
455 | { |
456 | throw new AssertionException(message); |
457 | } |
458 | } |
459 | |
460 | /** |
461 | * Asserts that the given expected <code>byte</code> array argument is not equal to the actual <code>byte</code> |
462 | * array argument. |
463 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
464 | * to the semantics of |
465 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(byte[], byte[])">the java.util.Arrays equals(byte[], byte[]) method</a>. |
466 | * <br/> |
467 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
468 | * |
469 | * @param expected The expected value to test for inequality. |
470 | * @param actual The actual value to test for inequality. |
471 | * @param message The assertion message. |
472 | * @throws AssertionException If the given expected <code>byte</code> array argument is equal to the actual |
473 | * <code>byte</code> array argument. |
474 | */ |
475 | public static void assertNotEqual(final byte[] expected, final byte[] actual, final Object... message) throws AssertionException |
476 | { |
477 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
478 | { |
479 | throw new AssertionException(message); |
480 | } |
481 | } |
482 | |
483 | /** |
484 | * Asserts that the given expected <code>short</code> array argument is not equal to the actual <code>short</code> |
485 | * array argument. |
486 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
487 | * to the semantics of |
488 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(short[], short[])">the java.util.Arrays equals(short[], short[]) method</a>. |
489 | * <br/> |
490 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
491 | * |
492 | * @param expected The expected value to test for inequality. |
493 | * @param actual The actual value to test for inequality. |
494 | * @param message The assertion message. |
495 | * @throws AssertionException If the given expected <code>short</code> array argument is equal to the actual |
496 | * <code>short</code> array argument. |
497 | */ |
498 | public static void assertNotEqual(final short[] expected, final short[] actual, final Object... message) throws AssertionException |
499 | { |
500 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
501 | { |
502 | throw new AssertionException(message); |
503 | } |
504 | } |
505 | |
506 | /** |
507 | * Asserts that the given expected <code>char</code> array argument is not equal to the actual <code>char</code> |
508 | * array argument. |
509 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
510 | * to the semantics of |
511 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(char[], char[])">the java.util.Arrays equals(char[], char[]) method</a>. |
512 | * <br/> |
513 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
514 | * |
515 | * @param expected The expected value to test for inequality. |
516 | * @param actual The actual value to test for inequality. |
517 | * @param message The assertion message. |
518 | * @throws AssertionException If the given expected <code>char</code> array argument is equal to the actual |
519 | * <code>char</code> array argument. |
520 | */ |
521 | public static void assertNotEqual(final char[] expected, final char[] actual, final Object... message) throws AssertionException |
522 | { |
523 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
524 | { |
525 | throw new AssertionException(message); |
526 | } |
527 | } |
528 | |
529 | /** |
530 | * Asserts that the given expected <code>int</code> array argument is not equal to the actual <code>int</code> |
531 | * array argument. |
532 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
533 | * to the semantics of |
534 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(int[], int[])">the java.util.Arrays equals(int[], int[]) method</a>. |
535 | * <br/> |
536 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
537 | * |
538 | * @param expected The expected value to test for inequality. |
539 | * @param actual The actual value to test for inequality. |
540 | * @param message The assertion message. |
541 | * @throws AssertionException If the given expected <code>int</code> array argument is equal to the actual |
542 | * <code>int</code> array argument. |
543 | */ |
544 | public static void assertNotEqual(final int[] expected, final int[] actual, final Object... message) throws AssertionException |
545 | { |
546 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
547 | { |
548 | throw new AssertionException(message); |
549 | } |
550 | } |
551 | |
552 | /** |
553 | * Asserts that the given expected <code>long</code> array argument is not equal to the actual <code>long</code> |
554 | * array argument. |
555 | * Equality of two arrays references is determined by both referring to <code>null</code> or being equal according |
556 | * to the semantics of |
557 | * <a href="%j2se.api.spec%/java/util/Arrays.html#equals(long[], long[])">the java.util.Arrays equals(long[], long[]) method</a>. |
558 | * <br/> |
559 | * <code>expected == null && actual == null || (Arrays.equals(expected, actual))</code> |
560 | * |
561 | * @param expected The expected value to test for inequality. |
562 | * @param actual The actual value to test for inequality. |
563 | * @param message The assertion message. |
564 | * @throws AssertionException If the given expected <code>long</code> array argument is equal to the actual |
565 | * <code>long</code> array argument. |
566 | */ |
567 | public static void assertNotEqual(final long[] expected, final long[] actual, final Object... message) throws AssertionException |
568 | { |
569 | if(expected == null && actual == null || (Arrays.equals(expected, actual))) |
570 | { |
571 | throw new AssertionException(message); |
572 | } |
573 | } |
574 | |
575 | /** |
576 | * Asserts that the given expected <code>Object</code> argument is referring to the same object as the actual |
577 | * <code>Object</code> argument. |
578 | * <br/> |
579 | * <code>expected == actual</code> |
580 | * |
581 | * @param expected The expected value to test for sameness. |
582 | * @param actual The actual value to test for sameness. |
583 | * @param message The assertion message. |
584 | * @throws AssertionException If the given expected <code>Object</code> argument is not referring to the same object |
585 | * as the actual <code>Object</code> argument. |
586 | */ |
587 | public static void assertSame(final Object expected, final Object actual, final Object... message) throws AssertionException |
588 | { |
589 | if(expected != actual) |
590 | { |
591 | throw new AssertionException(message); |
592 | } |
593 | } |
594 | |
595 | /** |
596 | * Asserts that the given expected <code>Object</code> argument is not referring to the same object as the actual |
597 | * <code>Object</code> argument. |
598 | * <br/> |
599 | * <code>expected != actual</code> |
600 | * |
601 | * @param expected The expected value to test for equality. |
602 | * @param actual The actual value to test for equality. |
603 | * @param message The assertion message. |
604 | * @throws AssertionException If the given expected <code>Object</code> argument is referring to the same object as |
605 | * the actual <code>Object</code> argument. |
606 | */ |
607 | public static void assertNotSame(final Object expected, final Object actual, final Object... message) throws AssertionException |
608 | { |
609 | if(expected == actual) |
610 | { |
611 | throw new AssertionException(message); |
612 | } |
613 | } |
614 | } |