View Javadoc

1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.ezmorph.test;
18  
19  import java.util.List;
20  
21  import junit.framework.Assert;
22  
23  /**
24   * Provides assertions on arrays (primitive and objects).<br>
25   * All methods support multiple dimensional arrays.
26   *
27   * @author Andres Almiray <aalmiray@users.sourceforge.net>
28   */
29  public class ArrayAssertions extends Assert
30  {
31     /**
32      * Asserts that two boolean[] are equal.<br>
33      *
34      * @param expecteds
35      * @param actuals
36      */
37     public static void assertEquals( boolean[] expecteds, boolean[] actuals )
38     {
39        assertEquals( null, expecteds, actuals );
40     }
41  
42     /**
43      * Asserts that a boolean[] is equal to an Object[] (presumably an Boolean[])
44      *
45      * @param expecteds
46      * @param actuals
47      */
48     public static void assertEquals( boolean[] expecteds, Object[] actuals )
49     {
50        assertEquals( null, expecteds, actuals );
51     }
52  
53     /**
54      * Asserts that two byte[] are equal.<br>
55      *
56      * @param expecteds
57      * @param actuals
58      */
59     public static void assertEquals( byte[] expecteds, byte[] actuals )
60     {
61        assertEquals( null, expecteds, actuals );
62     }
63  
64     /**
65      * Asserts that a byte[] is equal to an Object[] (presumably an Byte[])
66      *
67      * @param expecteds
68      * @param actuals
69      */
70     public static void assertEquals( byte[] expecteds, Object[] actuals )
71     {
72        assertEquals( null, expecteds, actuals );
73     }
74  
75     /**
76      * Asserts that two char[] are equal.<br>
77      *
78      * @param expecteds
79      * @param actuals
80      */
81     public static void assertEquals( char[] expecteds, char[] actuals )
82     {
83        assertEquals( null, expecteds, actuals );
84     }
85  
86     /**
87      * Asserts that a char[] is equal to an Object[] (presumably an Character[])
88      *
89      * @param expecteds
90      * @param actuals
91      */
92     public static void assertEquals( char[] expecteds, Object[] actuals )
93     {
94        assertEquals( null, expecteds, actuals );
95     }
96  
97     /**
98      * Asserts that two double[] are equal.<br>
99      *
100     * @param expecteds
101     * @param actuals
102     */
103    public static void assertEquals( double[] expecteds, double[] actuals )
104    {
105       assertEquals( null, expecteds, actuals );
106    }
107 
108    /**
109     * Asserts that a double[] is equal to an Object[] (presumably an Double[])
110     *
111     * @param expecteds
112     * @param actuals
113     */
114    public static void assertEquals( double[] expecteds, Object[] actuals )
115    {
116       assertEquals( null, expecteds, actuals );
117    }
118 
119    /**
120     * Asserts that two float[] are equal.<br>
121     *
122     * @param expecteds
123     * @param actuals
124     */
125    public static void assertEquals( float[] expecteds, float[] actuals )
126    {
127       assertEquals( null, expecteds, actuals );
128    }
129 
130    /**
131     * Asserts that a float[] is equal to an Object[] (presumably an Float[])
132     *
133     * @param expecteds
134     * @param actuals
135     */
136    public static void assertEquals( float[] expecteds, Object[] actuals )
137    {
138       assertEquals( null, expecteds, actuals );
139    }
140 
141    /**
142     * Asserts that two int[] are equal.<br>
143     *
144     * @param expecteds
145     * @param actuals
146     */
147    public static void assertEquals( int[] expecteds, int[] actuals )
148    {
149       assertEquals( null, expecteds, actuals );
150    }
151 
152    /**
153     * Asserts that a int[] is equal to an Object[] (presumably an Integer[])
154     *
155     * @param expecteds
156     * @param actuals
157     */
158    public static void assertEquals( int[] expecteds, Object[] actuals )
159    {
160       assertEquals( null, expecteds, actuals );
161    }
162 
163    /**
164     * Asserts that two Lists are equal.<br>
165     *
166     * @param expecteds
167     * @param actuals
168     */
169    public static void assertEquals( List expecteds, List actuals )
170    {
171       assertEquals( null, expecteds, actuals );
172    }
173 
174    /**
175     * Asserts that two long[] are equal.<br>
176     *
177     * @param expecteds
178     * @param actuals
179     */
180    public static void assertEquals( long[] expecteds, long[] actuals )
181    {
182       assertEquals( null, expecteds, actuals );
183    }
184 
185    /**
186     * Asserts that a long[] is equal to an Object[] (presumably an Long[])
187     *
188     * @param expecteds
189     * @param actuals
190     */
191    public static void assertEquals( long[] expecteds, Object[] actuals )
192    {
193       assertEquals( null, expecteds, actuals );
194    }
195 
196    /**
197     * Asserts that two objects are equal. If they are not an
198     * AssertionFailedError is thrown.
199     *
200     * @param expecteds
201     * @param actuals
202     */
203    public static void assertEquals( Object expected, Object actual )
204    {
205       assertEquals( null, expected, actual );
206    }
207 
208    /**
209     * Asserts that Object[] (presumably an Boolean[]) is equal to an boolean[].
210     *
211     * @param expecteds
212     * @param actuals
213     */
214    public static void assertEquals( Object[] expecteds, boolean[] actuals )
215    {
216       assertEquals( null, expecteds, actuals );
217    }
218 
219    /**
220     * Asserts that Object[] (presumably an Byte[]) is equal to an byte[].
221     *
222     * @param expecteds
223     * @param actuals
224     */
225    public static void assertEquals( Object[] expecteds, byte[] actuals )
226    {
227       assertEquals( null, expecteds, actuals );
228    }
229 
230    /**
231     * Asserts that Object[] (presumably an Character[]) is equal to an char[].
232     *
233     * @param expecteds
234     * @param actuals
235     */
236    public static void assertEquals( Object[] expecteds, char[] actuals )
237    {
238       assertEquals( null, expecteds, actuals );
239    }
240 
241    /**
242     * Asserts that Object[] (presumably an Double[]) is equal to an double[].
243     *
244     * @param expecteds
245     * @param actuals
246     */
247    public static void assertEquals( Object[] expecteds, double[] actuals )
248    {
249       assertEquals( null, expecteds, actuals );
250    }
251 
252    /**
253     * Asserts that Object[] (presumably an Float[]) is equal to an float[].
254     *
255     * @param expecteds
256     * @param actuals
257     */
258    public static void assertEquals( Object[] expecteds, float[] actuals )
259    {
260       assertEquals( null, expecteds, actuals );
261    }
262 
263    /**
264     * Asserts that Object[] (presumably an Integer[]) is equal to an int[].
265     *
266     * @param expecteds
267     * @param actuals
268     */
269    public static void assertEquals( Object[] expecteds, int[] actuals )
270    {
271       assertEquals( null, expecteds, actuals );
272    }
273 
274    /**
275     * Asserts that Object[] (presumably an Long[]) is equal to an long[].
276     *
277     * @param expecteds
278     * @param actuals
279     */
280    public static void assertEquals( Object[] expecteds, long[] actuals )
281    {
282       assertEquals( null, expecteds, actuals );
283    }
284 
285    /**
286     * Asserts that two Object[] are equal.<br>
287     *
288     * @param expecteds
289     * @param actuals
290     */
291    public static void assertEquals( Object[] expecteds, Object[] actuals )
292    {
293       assertEquals( null, expecteds, actuals );
294    }
295 
296    /**
297     * Asserts that Object[] (presumably an Short[]) is equal to an short[].
298     *
299     * @param expecteds
300     * @param actuals
301     */
302    public static void assertEquals( Object[] expecteds, short[] actuals )
303    {
304       assertEquals( null, expecteds, actuals );
305    }
306 
307    /**
308     * Asserts that a short[] is equal to an Object[] (presumably an Short[])
309     *
310     * @param expecteds
311     * @param actuals
312     */
313    public static void assertEquals( short[] expecteds, Object[] actuals )
314    {
315       assertEquals( null, expecteds, actuals );
316    }
317 
318    /**
319     * Asserts that two short[] are equal.<br>
320     *
321     * @param expecteds
322     * @param actuals
323     */
324    public static void assertEquals( short[] expecteds, short[] actuals )
325    {
326       assertEquals( null, expecteds, actuals );
327    }
328 
329    /**
330     * Asserts that two boolean[] are equal.<br>
331     *
332     * @param message
333     * @param expecteds
334     * @param actuals
335     */
336    public static void assertEquals( String message, boolean[] expecteds, boolean[] actuals )
337    {
338       if( expecteds == actuals ){
339          return;
340       }
341       String header = message == null ? "" : message + ": ";
342       if( expecteds == null ){
343          fail( header + "expected array was null" );
344       }
345       if( actuals == null ){
346          fail( header + "actual array was null" );
347       }
348       if( actuals.length != expecteds.length ){
349          fail( header + "array lengths differed, expected.length=" + expecteds.length
350                + " actual.length=" + actuals.length );
351       }
352 
353       for( int i = 0; i < expecteds.length; i++ ){
354          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
355                actuals[i] );
356       }
357    }
358 
359    /**
360     * Asserts that a boolean[] is equal to an Object[] (presumably an Boolean[])
361     *
362     * @param message
363     * @param expecteds
364     * @param actuals
365     */
366    public static void assertEquals( String message, boolean[] expecteds, Object[] actuals )
367    {
368       String header = message == null ? "" : message + ": ";
369       if( expecteds == null ){
370          fail( header + "expected array was null" );
371       }
372       if( actuals == null ){
373          fail( header + "actual array was null" );
374       }
375       if( actuals.length != expecteds.length ){
376          fail( header + "array lengths differed, expected.length=" + expecteds.length
377                + " actual.length=" + actuals.length );
378       }
379 
380       for( int i = 0; i < expecteds.length; i++ ){
381          assertEquals( header + "arrays first differed at element [" + i + "];", new Boolean(
382                expecteds[i] ), actuals[i] );
383       }
384    }
385 
386    /**
387     * Asserts that two byte[] are equal.<br>
388     *
389     * @param message
390     * @param expecteds
391     * @param actuals
392     */
393    public static void assertEquals( String message, byte[] expecteds, byte[] actuals )
394    {
395       if( expecteds == actuals ){
396          return;
397       }
398       String header = message == null ? "" : message + ": ";
399       if( expecteds == null ){
400          fail( header + "expected array was null" );
401       }
402       if( actuals == null ){
403          fail( header + "actual array was null" );
404       }
405       if( actuals.length != expecteds.length ){
406          fail( header + "array lengths differed, expected.length=" + expecteds.length
407                + " actual.length=" + actuals.length );
408       }
409 
410       for( int i = 0; i < expecteds.length; i++ ){
411          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
412                actuals[i] );
413       }
414    }
415 
416    /**
417     * Asserts that a byte[] is equal to an Object[] (presumably an Byte[])
418     *
419     * @param message
420     * @param expecteds
421     * @param actuals
422     */
423    public static void assertEquals( String message, byte[] expecteds, Object[] actuals )
424    {
425       String header = message == null ? "" : message + ": ";
426       if( expecteds == null ){
427          fail( header + "expected array was null" );
428       }
429       if( actuals == null ){
430          fail( header + "actual array was null" );
431       }
432       if( actuals.length != expecteds.length ){
433          fail( header + "array lengths differed, expected.length=" + expecteds.length
434                + " actual.length=" + actuals.length );
435       }
436 
437       for( int i = 0; i < expecteds.length; i++ ){
438          assertEquals( header + "arrays first differed at element [" + i + "];", new Byte(
439                expecteds[i] ), actuals[i] );
440       }
441    }
442 
443    /**
444     * Asserts that two char[] are equal.<br>
445     *
446     * @param message
447     * @param expecteds
448     * @param actuals
449     */
450    public static void assertEquals( String message, char[] expecteds, char[] actuals )
451    {
452       if( expecteds == actuals ){
453          return;
454       }
455       String header = message == null ? "" : message + ": ";
456       if( expecteds == null ){
457          fail( header + "expected array was null" );
458       }
459       if( actuals == null ){
460          fail( header + "actual array was null" );
461       }
462       if( actuals.length != expecteds.length ){
463          fail( header + "array lengths differed, expected.length=" + expecteds.length
464                + " actual.length=" + actuals.length );
465       }
466 
467       for( int i = 0; i < expecteds.length; i++ ){
468          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
469                actuals[i] );
470       }
471    }
472 
473    /**
474     * Asserts that a char[] is equal to an Object[] (presumably an Character[])
475     *
476     * @param message
477     * @param expecteds
478     * @param actuals
479     */
480    public static void assertEquals( String message, char[] expecteds, Object[] actuals )
481    {
482       String header = message == null ? "" : message + ": ";
483       if( expecteds == null ){
484          fail( header + "expected array was null" );
485       }
486       if( actuals == null ){
487          fail( header + "actual array was null" );
488       }
489       if( actuals.length != expecteds.length ){
490          fail( header + "array lengths differed, expected.length=" + expecteds.length
491                + " actual.length=" + actuals.length );
492       }
493 
494       for( int i = 0; i < expecteds.length; i++ ){
495          assertEquals( header + "arrays first differed at element [" + i + "];", new Character(
496                expecteds[i] ), actuals[i] );
497       }
498    }
499 
500    /**
501     * Asserts that two double[] are equal.<br>
502     *
503     * @param message
504     * @param expecteds
505     * @param actuals
506     */
507    public static void assertEquals( String message, double[] expecteds, double[] actuals )
508    {
509       if( expecteds == actuals ){
510          return;
511       }
512       String header = message == null ? "" : message + ": ";
513       if( expecteds == null ){
514          fail( header + "expected array was null" );
515       }
516       if( actuals == null ){
517          fail( header + "actual array was null" );
518       }
519       if( actuals.length != expecteds.length ){
520          fail( header + "array lengths differed, expected.length=" + expecteds.length
521                + " actual.length=" + actuals.length );
522       }
523 
524       for( int i = 0; i < expecteds.length; i++ ){
525          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
526                actuals[i], 0d );
527       }
528    }
529 
530    /**
531     * Asserts that a double[] is equal to an Object[] (presumably an Double[])
532     *
533     * @param message
534     * @param expecteds
535     * @param actuals
536     */
537    public static void assertEquals( String message, double[] expecteds, Object[] actuals )
538    {
539       String header = message == null ? "" : message + ": ";
540       if( expecteds == null ){
541          fail( header + "expected array was null" );
542       }
543       if( actuals == null ){
544          fail( header + "actual array was null" );
545       }
546       if( actuals.length != expecteds.length ){
547          fail( header + "array lengths differed, expected.length=" + expecteds.length
548                + " actual.length=" + actuals.length );
549       }
550 
551       for( int i = 0; i < expecteds.length; i++ ){
552          assertEquals( header + "arrays first differed at element [" + i + "];", new Double(
553                expecteds[i] ), actuals[i] );
554       }
555    }
556 
557    /**
558     * Asserts that two float[] are equal.<br>
559     *
560     * @param message
561     * @param expecteds
562     * @param actuals
563     */
564    public static void assertEquals( String message, float[] expecteds, float[] actuals )
565    {
566       if( expecteds == actuals ){
567          return;
568       }
569       String header = message == null ? "" : message + ": ";
570       if( expecteds == null ){
571          fail( header + "expected array was null" );
572       }
573       if( actuals == null ){
574          fail( header + "actual array was null" );
575       }
576       if( actuals.length != expecteds.length ){
577          fail( header + "array lengths differed, expected.length=" + expecteds.length
578                + " actual.length=" + actuals.length );
579       }
580 
581       for( int i = 0; i < expecteds.length; i++ ){
582          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
583                actuals[i], 0f );
584       }
585    }
586 
587    /**
588     * Asserts that a float[] is equal to an Object[] (presumably an Float[])
589     *
590     * @param message
591     * @param expecteds
592     * @param actuals
593     */
594    public static void assertEquals( String message, float[] expecteds, Object[] actuals )
595    {
596       String header = message == null ? "" : message + ": ";
597       if( expecteds == null ){
598          fail( header + "expected array was null" );
599       }
600       if( actuals == null ){
601          fail( header + "actual array was null" );
602       }
603       if( actuals.length != expecteds.length ){
604          fail( header + "array lengths differed, expected.length=" + expecteds.length
605                + " actual.length=" + actuals.length );
606       }
607 
608       for( int i = 0; i < expecteds.length; i++ ){
609          assertEquals( header + "arrays first differed at element [" + i + "];", new Float(
610                expecteds[i] ), actuals[i] );
611       }
612    }
613 
614    /**
615     * Asserts that two int[] are equal.<br>
616     *
617     * @param message
618     * @param expecteds
619     * @param actuals
620     */
621    public static void assertEquals( String message, int[] expecteds, int[] actuals )
622    {
623       if( expecteds == actuals ){
624          return;
625       }
626       String header = message == null ? "" : message + ": ";
627       if( expecteds == null ){
628          fail( header + "expected array was null" );
629       }
630       if( actuals == null ){
631          fail( header + "actual array was null" );
632       }
633       if( actuals.length != expecteds.length ){
634          fail( header + "array lengths differed, expected.length=" + expecteds.length
635                + " actual.length=" + actuals.length );
636       }
637 
638       for( int i = 0; i < expecteds.length; i++ ){
639          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
640                actuals[i] );
641       }
642    }
643 
644    /**
645     * Asserts that a int[] is equal to an Object[] (presumably an Integer[])
646     *
647     * @param message
648     * @param expecteds
649     * @param actuals
650     */
651    public static void assertEquals( String message, int[] expecteds, Object[] actuals )
652    {
653       String header = message == null ? "" : message + ": ";
654       if( expecteds == null ){
655          fail( header + "expected array was null" );
656       }
657       if( actuals == null ){
658          fail( header + "actual array was null" );
659       }
660       if( actuals.length != expecteds.length ){
661          fail( header + "array lengths differed, expected.length=" + expecteds.length
662                + " actual.length=" + actuals.length );
663       }
664 
665       for( int i = 0; i < expecteds.length; i++ ){
666          assertEquals( header + "arrays first differed at element [" + i + "];", new Integer(
667                expecteds[i] ), actuals[i] );
668       }
669    }
670 
671    /**
672     * Asserts that two Lists are equal.<br>
673     *
674     * @param message
675     * @param expecteds
676     * @param actuals
677     */
678    public static void assertEquals( String message, List expecteds, List actuals )
679    {
680       String header = message == null ? "" : message + ": ";
681       if( expecteds == null ){
682          fail( header + "expected list was null" );
683       }
684       if( actuals == null ){
685          fail( header + "actual list was null" );
686       }
687       if( expecteds == actuals || expecteds.equals( actuals ) ){
688          return;
689       }
690       if( actuals.size() != expecteds.size() ){
691          fail( header + "list sizes differed, expected.size()=" + expecteds.size()
692                + " actual.size()=" + actuals.size() );
693       }
694 
695       int max = expecteds.size();
696       for( int i = 0; i < max; i++ ){
697          Object o1 = expecteds.get( i );
698          Object o2 = actuals.get( i );
699 
700          // handle nulls
701          if( o1 == null ){
702             if( o2 == null ){
703                return;
704             }else{
705                fail( header + "lists first differed at element [" + i + "];" );
706             }
707          }else{
708             if( o2 == null ){
709                fail( header + "lists first differed at element [" + i + "];" );
710             }
711          }
712 
713          if( o1.getClass()
714                .isArray() && o2.getClass()
715                .isArray() ){
716             Object[] expected = (Object[]) o1;
717             Object[] actual = (Object[]) o2;
718             assertEquals( header + "lists first differed at element " + i + ";", expected, actual );
719          }else if( List.class.isAssignableFrom( o1.getClass() )
720                && List.class.isAssignableFrom( o2.getClass() ) ){
721             assertEquals( header + "lists first differed at element [" + i + "];", (List) o1,
722                   (List) o2 );
723          }else{
724             assertEquals( header + "lists first differed at element [" + i + "];", o1, o2 );
725          }
726       }
727    }
728 
729    /**
730     * Asserts that two long[] are equal.<br>
731     *
732     * @param message
733     * @param expecteds
734     * @param actuals
735     */
736    public static void assertEquals( String message, long[] expecteds, long[] actuals )
737    {
738       if( expecteds == actuals ){
739          return;
740       }
741       String header = message == null ? "" : message + ": ";
742       if( expecteds == null ){
743          fail( header + "expected array was null" );
744       }
745       if( actuals == null ){
746          fail( header + "actual array was null" );
747       }
748       if( actuals.length != expecteds.length ){
749          fail( header + "array lengths differed, expected.length=" + expecteds.length
750                + " actual.length=" + actuals.length );
751       }
752 
753       for( int i = 0; i < expecteds.length; i++ ){
754          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
755                actuals[i] );
756       }
757    }
758 
759    /**
760     * Asserts that a long[] is equal to an Object[] (presumably an Long[])
761     *
762     * @param message
763     * @param expecteds
764     * @param actuals
765     */
766    public static void assertEquals( String message, long[] expecteds, Object[] actuals )
767    {
768       String header = message == null ? "" : message + ": ";
769       if( expecteds == null ){
770          fail( header + "expected array was null" );
771       }
772       if( actuals == null ){
773          fail( header + "actual array was null" );
774       }
775       if( actuals.length != expecteds.length ){
776          fail( header + "array lengths differed, expected.length=" + expecteds.length
777                + " actual.length=" + actuals.length );
778       }
779 
780       for( int i = 0; i < expecteds.length; i++ ){
781          assertEquals( header + "arrays first differed at element [" + i + "];", new Long(
782                expecteds[i] ), actuals[i] );
783       }
784    }
785 
786    /**
787     * Asserts that two objects are equal. If they are not an
788     * AssertionFailedError is thrown with the given message. *
789     *
790     * @param message
791     * @param expecteds
792     * @param actuals
793     */
794    public static void assertEquals( String message, Object expected, Object actual )
795    {
796       if( expected == null && actual == null )
797          return;
798       if( expected != null && expected.equals( actual ) )
799          return;
800       Class expectedClass = expected.getClass();
801       Class actualClass = actual.getClass();
802       if( expectedClass.isArray() && actualClass.isArray() ){
803          Class expectedInnerType = expectedClass.getComponentType();
804          Class actualInnerType = actualClass.getComponentType();
805          if( expectedInnerType.isPrimitive() ){
806             assertExpectedPrimitiveArrays( message, expected, actual, expectedInnerType,
807                   actualInnerType );
808          }else if( actualInnerType.isPrimitive() ){
809             assertActualPrimitiveArrays( message, expected, actual, expectedInnerType,
810                   actualInnerType );
811          }else{
812             assertEquals( message, (Object[]) expected, (Object[]) actual );
813          }
814       }else{
815          failNotEquals( message, expected, actual );
816       }
817    }
818 
819    /**
820     * Asserts that Object[] (presumably an Boolean[]) is equal to an boolean[].
821     *
822     * @param message
823     * @param expecteds
824     * @param actuals
825     */
826    public static void assertEquals( String message, Object[] expecteds, boolean[] actuals )
827    {
828       String header = message == null ? "" : message + ": ";
829       if( expecteds == null ){
830          fail( header + "expected array was null" );
831       }
832       if( actuals == null ){
833          fail( header + "actual array was null" );
834       }
835       if( actuals.length != expecteds.length ){
836          fail( header + "array lengths differed, expected.length=" + expecteds.length
837                + " actual.length=" + actuals.length );
838       }
839 
840       for( int i = 0; i < expecteds.length; i++ ){
841          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
842                new Boolean( actuals[i] ) );
843       }
844    }
845 
846    /**
847     * Asserts that Object[] (presumably an Byte[]) is equal to an byte[].
848     *
849     * @param message
850     * @param expecteds
851     * @param actuals
852     */
853    public static void assertEquals( String message, Object[] expecteds, byte[] actuals )
854    {
855       String header = message == null ? "" : message + ": ";
856       if( expecteds == null ){
857          fail( header + "expected array was null" );
858       }
859       if( actuals == null ){
860          fail( header + "actual array was null" );
861       }
862       if( actuals.length != expecteds.length ){
863          fail( header + "array lengths differed, expected.length=" + expecteds.length
864                + " actual.length=" + actuals.length );
865       }
866 
867       for( int i = 0; i < expecteds.length; i++ ){
868          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
869                new Byte( actuals[i] ) );
870       }
871    }
872 
873    /**
874     * Asserts that Object[] (presumably an Character[]) is equal to an char[].
875     *
876     * @param message
877     * @param expecteds
878     * @param actuals
879     */
880    public static void assertEquals( String message, Object[] expecteds, char[] actuals )
881    {
882       String header = message == null ? "" : message + ": ";
883       if( expecteds == null ){
884          fail( header + "expected array was null" );
885       }
886       if( actuals == null ){
887          fail( header + "actual array was null" );
888       }
889       if( actuals.length != expecteds.length ){
890          fail( header + "array lengths differed, expected.length=" + expecteds.length
891                + " actual.length=" + actuals.length );
892       }
893 
894       for( int i = 0; i < expecteds.length; i++ ){
895          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
896                new Character( actuals[i] ) );
897       }
898    }
899 
900    /**
901     * Asserts that Object[] (presumably an Double[]) is equal to an double[].
902     *
903     * @param message
904     * @param expecteds
905     * @param actuals
906     */
907    public static void assertEquals( String message, Object[] expecteds, double[] actuals )
908    {
909       String header = message == null ? "" : message + ": ";
910       if( expecteds == null ){
911          fail( header + "expected array was null" );
912       }
913       if( actuals == null ){
914          fail( header + "actual array was null" );
915       }
916       if( actuals.length != expecteds.length ){
917          fail( header + "array lengths differed, expected.length=" + expecteds.length
918                + " actual.length=" + actuals.length );
919       }
920 
921       for( int i = 0; i < expecteds.length; i++ ){
922          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
923                new Double( actuals[i] ) );
924       }
925    }
926 
927    /**
928     * Asserts that Object[] (presumably an Float[]) is equal to an float[].
929     *
930     * @param message
931     * @param expecteds
932     * @param actuals
933     */
934    public static void assertEquals( String message, Object[] expecteds, float[] actuals )
935    {
936       String header = message == null ? "" : message + ": ";
937       if( expecteds == null ){
938          fail( header + "expected array was null" );
939       }
940       if( actuals == null ){
941          fail( header + "actual array was null" );
942       }
943       if( actuals.length != expecteds.length ){
944          fail( header + "array lengths differed, expected.length=" + expecteds.length
945                + " actual.length=" + actuals.length );
946       }
947 
948       for( int i = 0; i < expecteds.length; i++ ){
949          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
950                new Float( actuals[i] ) );
951       }
952    }
953 
954    /**
955     * Asserts that Object[] (presumably an Integer[]) is equal to an int[].
956     *
957     * @param message
958     * @param expecteds
959     * @param actuals
960     */
961    public static void assertEquals( String message, Object[] expecteds, int[] actuals )
962    {
963       String header = message == null ? "" : message + ": ";
964       if( expecteds == null ){
965          fail( header + "expected array was null" );
966       }
967       if( actuals == null ){
968          fail( header + "actual array was null" );
969       }
970       if( actuals.length != expecteds.length ){
971          fail( header + "array lengths differed, expected.length=" + expecteds.length
972                + " actual.length=" + actuals.length );
973       }
974 
975       for( int i = 0; i < expecteds.length; i++ ){
976          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
977                new Integer( actuals[i] ) );
978       }
979    }
980 
981    /**
982     * Asserts that Object[] (presumably an Long[]) is equal to an long[].
983     *
984     * @param message
985     * @param expecteds
986     * @param actuals
987     */
988    public static void assertEquals( String message, Object[] expecteds, long[] actuals )
989    {
990       String header = message == null ? "" : message + ": ";
991       if( expecteds == null ){
992          fail( header + "expected array was null" );
993       }
994       if( actuals == null ){
995          fail( header + "actual array was null" );
996       }
997       if( actuals.length != expecteds.length ){
998          fail( header + "array lengths differed, expected.length=" + expecteds.length
999                + " actual.length=" + actuals.length );
1000       }
1001 
1002       for( int i = 0; i < expecteds.length; i++ ){
1003          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
1004                new Long( actuals[i] ) );
1005       }
1006    }
1007 
1008    /**
1009     * Asserts that two Object[] are equal.<br>
1010     *
1011     * @param message
1012     * @param expecteds
1013     * @param actuals
1014     */
1015    public static void assertEquals( String message, Object[] expecteds, Object[] actuals )
1016    {
1017       if( expecteds == actuals ){
1018          return;
1019       }
1020       String header = message == null ? "" : message + ": ";
1021       if( expecteds == null ){
1022          fail( header + "expected array was null" );
1023       }
1024       if( actuals == null ){
1025          fail( header + "actual array was null" );
1026       }
1027       if( actuals.length != expecteds.length ){
1028          fail( header + "array lengths differed, expected.length=" + expecteds.length
1029                + " actual.length=" + actuals.length );
1030       }
1031 
1032       for( int i = 0; i < expecteds.length; i++ ){
1033          Object o1 = expecteds[i];
1034          Object o2 = actuals[i];
1035 
1036          if( o1 == null ){
1037             if( o2 == null ){
1038                return;
1039             }else{
1040                fail( header + "arrays first differed at element [" + i + "];" );
1041             }
1042          }else{
1043             if( o2 == null ){
1044                fail( header + "arrays first differed at element [" + i + "];" );
1045             }
1046          }
1047 
1048          if( o1.getClass()
1049                .isArray() && o2.getClass()
1050                .isArray() ){
1051             Class type1 = o1.getClass()
1052                   .getComponentType();
1053             Class type2 = o2.getClass()
1054                   .getComponentType();
1055             if( type1.isPrimitive() ){
1056                if( type1 == Boolean.TYPE ){
1057                   if( type2 == Boolean.TYPE ){
1058                      assertEquals( header + "arrays first differed at element " + i + ";",
1059                            (boolean[]) o1, (boolean[]) o2 );
1060                   }else{
1061                      assertEquals( header + "arrays first differed at element " + i + ";",
1062                            (boolean[]) o1, (Object[]) o2 );
1063                   }
1064                }else if( type1 == Byte.TYPE ){
1065                   if( type2 == Byte.TYPE ){
1066                      assertEquals( header + "arrays first differed at element " + i + ";",
1067                            (byte[]) o1, (byte[]) o2 );
1068                   }else{
1069                      assertEquals( header + "arrays first differed at element " + i + ";",
1070                            (byte[]) o1, (Object[]) o2 );
1071                   }
1072                }else if( type1 == Short.TYPE ){
1073                   if( type2 == Short.TYPE ){
1074                      assertEquals( header + "arrays first differed at element " + i + ";",
1075                            (short[]) o1, (short[]) o2 );
1076                   }else{
1077                      assertEquals( header + "arrays first differed at element " + i + ";",
1078                            (short[]) o1, (Object[]) o2 );
1079                   }
1080                }else if( type1 == Integer.TYPE ){
1081                   if( type2 == Integer.TYPE ){
1082                      assertEquals( header + "arrays first differed at element " + i + ";",
1083                            (int[]) o1, (int[]) o2 );
1084                   }else{
1085                      assertEquals( header + "arrays first differed at element " + i + ";",
1086                            (int[]) o1, (Object[]) o2 );
1087                   }
1088                }else if( type1 == Long.TYPE ){
1089                   if( type2 == Long.TYPE ){
1090                      assertEquals( header + "arrays first differed at element " + i + ";",
1091                            (long[]) o1, (long[]) o2 );
1092                   }else{
1093                      assertEquals( header + "arrays first differed at element " + i + ";",
1094                            (long[]) o1, (Object[]) o2 );
1095                   }
1096                }else if( type1 == Float.TYPE ){
1097                   if( type2 == Float.TYPE ){
1098                      assertEquals( header + "arrays first differed at element " + i + ";",
1099                            (float[]) o1, (float[]) o2 );
1100                   }else{
1101                      assertEquals( header + "arrays first differed at element " + i + ";",
1102                            (float[]) o1, (Object[]) o2 );
1103                   }
1104                }else if( type1 == Double.TYPE ){
1105                   if( type2 == Double.TYPE ){
1106                      assertEquals( header + "arrays first differed at element " + i + ";",
1107                            (double[]) o1, (double[]) o2 );
1108                   }else{
1109                      assertEquals( header + "arrays first differed at element " + i + ";",
1110                            (double[]) o1, (Object[]) o2 );
1111                   }
1112                }else if( type1 == Character.TYPE ){
1113                   if( type2 == Character.TYPE ){
1114                      assertEquals( header + "arrays first differed at element " + i + ";",
1115                            (char[]) o1, (char[]) o2 );
1116                   }else{
1117                      assertEquals( header + "arrays first differed at element " + i + ";",
1118                            (char[]) o1, (Object[]) o2 );
1119                   }
1120                }
1121             }else if( type2.isPrimitive() ){
1122                if( type2 == Boolean.TYPE ){
1123                   assertEquals( header + "arrays first differed at element " + i + ";",
1124                         (Object[]) o1, (boolean[]) o2 );
1125                }else if( type2 == Byte.TYPE ){
1126                   assertEquals( header + "arrays first differed at element " + i + ";",
1127                         (Object[]) o1, (byte[]) o2 );
1128                }else if( type2 == Short.TYPE ){
1129                   assertEquals( header + "arrays first differed at element " + i + ";",
1130                         (Object[]) o1, (short[]) o2 );
1131                }else if( type2 == Integer.TYPE ){
1132                   assertEquals( header + "arrays first differed at element " + i + ";",
1133                         (Object[]) o1, (int[]) o2 );
1134                }else if( type2 == Long.TYPE ){
1135                   assertEquals( header + "arrays first differed at element " + i + ";",
1136                         (Object[]) o1, (long[]) o2 );
1137                }else if( type2 == Float.TYPE ){
1138                   assertEquals( header + "arrays first differed at element " + i + ";",
1139                         (Object[]) o1, (float[]) o2 );
1140                }else if( type2 == Double.TYPE ){
1141                   assertEquals( header + "arrays first differed at element " + i + ";",
1142                         (Object[]) o1, (double[]) o2 );
1143                }else if( type2 == Character.TYPE ){
1144                   assertEquals( header + "arrays first differed at element " + i + ";",
1145                         (Object[]) o1, (char[]) o2 );
1146                }
1147             }else{
1148                Object[] expected = (Object[]) o1;
1149                Object[] actual = (Object[]) o2;
1150                assertEquals( header + "arrays first differed at element " + i + ";", expected,
1151                      actual );
1152             }
1153          }else{
1154             assertEquals( header + "arrays first differed at element [" + i + "];", o1, o2 );
1155          }
1156       }
1157    }
1158 
1159    /**
1160     * Asserts that Object[] (presumably an Short[]) is equal to a short[].
1161     *
1162     * @param message
1163     * @param expecteds
1164     * @param actuals
1165     */
1166    public static void assertEquals( String message, Object[] expecteds, short[] actuals )
1167    {
1168       String header = message == null ? "" : message + ": ";
1169       if( expecteds == null ){
1170          fail( header + "expected array was null" );
1171       }
1172       if( actuals == null ){
1173          fail( header + "actual array was null" );
1174       }
1175       if( actuals.length != expecteds.length ){
1176          fail( header + "array lengths differed, expected.length=" + expecteds.length
1177                + " actual.length=" + actuals.length );
1178       }
1179 
1180       for( int i = 0; i < expecteds.length; i++ ){
1181          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
1182                new Short( actuals[i] ) );
1183       }
1184    }
1185 
1186    /**
1187     * Asserts that a short[] is equal to an Object[] (presumably an Short[])
1188     *
1189     * @param message
1190     * @param expecteds
1191     * @param actuals
1192     */
1193    public static void assertEquals( String message, short[] expecteds, Object[] actuals )
1194    {
1195       String header = message == null ? "" : message + ": ";
1196       if( expecteds == null ){
1197          fail( header + "expected array was null" );
1198       }
1199       if( actuals == null ){
1200          fail( header + "actual array was null" );
1201       }
1202       if( actuals.length != expecteds.length ){
1203          fail( header + "array lengths differed, expected.length=" + expecteds.length
1204                + " actual.length=" + actuals.length );
1205       }
1206 
1207       for( int i = 0; i < expecteds.length; i++ ){
1208          assertEquals( header + "arrays first differed at element [" + i + "];", new Short(
1209                expecteds[i] ), actuals[i] );
1210       }
1211    }
1212 
1213    /**
1214     * Asserts that two short[] are equal.<br>
1215     *
1216     * @param message
1217     * @param expecteds
1218     * @param actuals
1219     */
1220    public static void assertEquals( String message, short[] expecteds, short[] actuals )
1221    {
1222       if( expecteds == actuals ){
1223          return;
1224       }
1225       String header = message == null ? "" : message + ": ";
1226       if( expecteds == null ){
1227          fail( header + "expected array was null" );
1228       }
1229       if( actuals == null ){
1230          fail( header + "actual array was null" );
1231       }
1232       if( actuals.length != expecteds.length ){
1233          fail( header + "array lengths differed, expected.length=" + expecteds.length
1234                + " actual.length=" + actuals.length );
1235       }
1236 
1237       for( int i = 0; i < expecteds.length; i++ ){
1238          assertEquals( header + "arrays first differed at element [" + i + "];", expecteds[i],
1239                actuals[i] );
1240       }
1241    }
1242 
1243    private static void assertActualPrimitiveArrays( String message, Object expected, Object actual,
1244          Class expectedInnerType, Class actualInnerType )
1245    {
1246       if( Boolean.TYPE.isAssignableFrom( actualInnerType ) ){
1247          if( Boolean.class.isAssignableFrom( expectedInnerType ) ){
1248             assertEquals( message, (Boolean[]) expected, (boolean[]) actual );
1249          }else{
1250             assertEquals( message, (Object[]) expected, (boolean[]) actual );
1251          }
1252       }else if( Byte.TYPE.isAssignableFrom( actualInnerType ) ){
1253          if( Byte.class.isAssignableFrom( expectedInnerType ) ){
1254             assertEquals( message, (Byte[]) expected, (byte[]) actual );
1255          }else{
1256             assertEquals( message, (Object[]) expected, (byte[]) actual );
1257          }
1258       }else if( Short.TYPE.isAssignableFrom( actualInnerType ) ){
1259          if( Short.class.isAssignableFrom( expectedInnerType ) ){
1260             assertEquals( message, (Short[]) expected, (short[]) actual );
1261          }else{
1262             assertEquals( message, (Object[]) expected, (short[]) actual );
1263          }
1264       }else if( Integer.TYPE.isAssignableFrom( actualInnerType ) ){
1265          if( Integer.class.isAssignableFrom( expectedInnerType ) ){
1266             assertEquals( message, (Integer[]) expected, (int[]) actual );
1267          }else{
1268             assertEquals( message, (Object[]) expected, (int[]) actual );
1269          }
1270       }else if( Long.TYPE.isAssignableFrom( actualInnerType ) ){
1271          if( Long.class.isAssignableFrom( expectedInnerType ) ){
1272             assertEquals( message, (Long[]) expected, (long[]) actual );
1273          }else{
1274             assertEquals( message, (Object[]) expected, (long[]) actual );
1275          }
1276       }else if( Float.TYPE.isAssignableFrom( actualInnerType ) ){
1277          if( Float.class.isAssignableFrom( expectedInnerType ) ){
1278             assertEquals( message, (Float[]) expected, (float[]) actual );
1279          }else{
1280             assertEquals( message, (Object[]) expected, (float[]) actual );
1281          }
1282       }else if( Double.TYPE.isAssignableFrom( actualInnerType ) ){
1283          if( Double.class.isAssignableFrom( expectedInnerType ) ){
1284             assertEquals( message, (Double[]) expected, (double[]) actual );
1285          }else{
1286             assertEquals( message, (Object[]) expected, (double[]) actual );
1287          }
1288       }else if( Character.TYPE.isAssignableFrom( actualInnerType ) ){
1289          if( Character.class.isAssignableFrom( expectedInnerType ) ){
1290             assertEquals( message, (Character[]) expected, (char[]) actual );
1291          }else{
1292             assertEquals( message, (Object[]) expected, (char[]) actual );
1293          }
1294       }
1295    }
1296 
1297    private static void assertExpectedPrimitiveArrays( String message, Object expected,
1298          Object actual, Class expectedInnerType, Class actualInnerType )
1299    {
1300       if( Boolean.TYPE.isAssignableFrom( expectedInnerType ) ){
1301          if( Boolean.TYPE.isAssignableFrom( actualInnerType ) ){
1302             assertEquals( message, (boolean[]) expected, (boolean[]) actual );
1303          }else if( Boolean.class.isAssignableFrom( actualInnerType ) ){
1304             assertEquals( message, (boolean[]) expected, (Boolean[]) actual );
1305          }else if( !actualInnerType.isPrimitive() ){
1306             assertEquals( message, (boolean[]) expected, (Object[]) actual );
1307          }else{
1308             failNotEquals( message, expected, actual );
1309          }
1310       }else if( Byte.TYPE.isAssignableFrom( expectedInnerType ) ){
1311          if( Byte.TYPE.isAssignableFrom( actualInnerType ) ){
1312             assertEquals( message, (byte[]) expected, (byte[]) actual );
1313          }else if( Byte.class.isAssignableFrom( actualInnerType ) ){
1314             assertEquals( message, (byte[]) expected, (Byte[]) actual );
1315          }else if( !actualInnerType.isPrimitive() ){
1316             assertEquals( message, (byte[]) expected, (Object[]) actual );
1317          }else{
1318             failNotEquals( message, expected, actual );
1319          }
1320       }else if( Short.TYPE.isAssignableFrom( expectedInnerType ) ){
1321          if( Short.TYPE.isAssignableFrom( actualInnerType ) ){
1322             assertEquals( message, (short[]) expected, (short[]) actual );
1323          }else if( Short.class.isAssignableFrom( actualInnerType ) ){
1324             assertEquals( message, (short[]) expected, (Short[]) actual );
1325          }else if( !actualInnerType.isPrimitive() ){
1326             assertEquals( message, (short[]) expected, (Object[]) actual );
1327          }else{
1328             failNotEquals( message, expected, actual );
1329          }
1330       }else if( Integer.TYPE.isAssignableFrom( expectedInnerType ) ){
1331          if( Integer.TYPE.isAssignableFrom( actualInnerType ) ){
1332             assertEquals( message, (int[]) expected, (int[]) actual );
1333          }else if( Integer.class.isAssignableFrom( actualInnerType ) ){
1334             assertEquals( message, (int[]) expected, (Integer[]) actual );
1335          }else if( !actualInnerType.isPrimitive() ){
1336             assertEquals( message, (int[]) expected, (Object[]) actual );
1337          }else{
1338             failNotEquals( message, expected, actual );
1339          }
1340       }else if( Long.TYPE.isAssignableFrom( expectedInnerType ) ){
1341          if( Long.TYPE.isAssignableFrom( actualInnerType ) ){
1342             assertEquals( message, (long[]) expected, (long[]) actual );
1343          }else if( Long.class.isAssignableFrom( actualInnerType ) ){
1344             assertEquals( message, (long[]) expected, (Long[]) actual );
1345          }else if( !actualInnerType.isPrimitive() ){
1346             assertEquals( message, (long[]) expected, (Object[]) actual );
1347          }else{
1348             failNotEquals( message, expected, actual );
1349          }
1350       }else if( Float.TYPE.isAssignableFrom( expectedInnerType ) ){
1351          if( Float.TYPE.isAssignableFrom( actualInnerType ) ){
1352             assertEquals( message, (float[]) expected, (float[]) actual );
1353          }else if( Float.class.isAssignableFrom( actualInnerType ) ){
1354             assertEquals( message, (float[]) expected, (Float[]) actual );
1355          }else if( !actualInnerType.isPrimitive() ){
1356             assertEquals( message, (float[]) expected, (Object[]) actual );
1357          }else{
1358             failNotEquals( message, expected, actual );
1359          }
1360       }else if( Double.TYPE.isAssignableFrom( expectedInnerType ) ){
1361          if( Double.TYPE.isAssignableFrom( actualInnerType ) ){
1362             assertEquals( message, (double[]) expected, (double[]) actual );
1363          }else if( Double.class.isAssignableFrom( actualInnerType ) ){
1364             assertEquals( message, (double[]) expected, (Double[]) actual );
1365          }else if( !actualInnerType.isPrimitive() ){
1366             assertEquals( message, (double[]) expected, (Object[]) actual );
1367          }else{
1368             failNotEquals( message, expected, actual );
1369          }
1370       }else if( Character.TYPE.isAssignableFrom( expectedInnerType ) ){
1371          if( Character.TYPE.isAssignableFrom( actualInnerType ) ){
1372             assertEquals( message, (char[]) expected, (char[]) actual );
1373          }else if( Character.class.isAssignableFrom( actualInnerType ) ){
1374             assertEquals( message, (char[]) expected, (Character[]) actual );
1375          }else if( !actualInnerType.isPrimitive() ){
1376             assertEquals( message, (char[]) expected, (Object[]) actual );
1377          }else{
1378             failNotEquals( message, expected, actual );
1379          }
1380       }
1381    }
1382 
1383    private ArrayAssertions()
1384    {
1385 
1386    }
1387 }