1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ezmorph.test;
18
19 import java.util.List;
20
21 import junit.framework.Assert;
22
23
24
25
26
27
28
29 public class ArrayAssertions extends Assert
30 {
31
32
33
34
35
36
37 public static void assertEquals( boolean[] expecteds, boolean[] actuals )
38 {
39 assertEquals( null, expecteds, actuals );
40 }
41
42
43
44
45
46
47
48 public static void assertEquals( boolean[] expecteds, Object[] actuals )
49 {
50 assertEquals( null, expecteds, actuals );
51 }
52
53
54
55
56
57
58
59 public static void assertEquals( byte[] expecteds, byte[] actuals )
60 {
61 assertEquals( null, expecteds, actuals );
62 }
63
64
65
66
67
68
69
70 public static void assertEquals( byte[] expecteds, Object[] actuals )
71 {
72 assertEquals( null, expecteds, actuals );
73 }
74
75
76
77
78
79
80
81 public static void assertEquals( char[] expecteds, char[] actuals )
82 {
83 assertEquals( null, expecteds, actuals );
84 }
85
86
87
88
89
90
91
92 public static void assertEquals( char[] expecteds, Object[] actuals )
93 {
94 assertEquals( null, expecteds, actuals );
95 }
96
97
98
99
100
101
102
103 public static void assertEquals( double[] expecteds, double[] actuals )
104 {
105 assertEquals( null, expecteds, actuals );
106 }
107
108
109
110
111
112
113
114 public static void assertEquals( double[] expecteds, Object[] actuals )
115 {
116 assertEquals( null, expecteds, actuals );
117 }
118
119
120
121
122
123
124
125 public static void assertEquals( float[] expecteds, float[] actuals )
126 {
127 assertEquals( null, expecteds, actuals );
128 }
129
130
131
132
133
134
135
136 public static void assertEquals( float[] expecteds, Object[] actuals )
137 {
138 assertEquals( null, expecteds, actuals );
139 }
140
141
142
143
144
145
146
147 public static void assertEquals( int[] expecteds, int[] actuals )
148 {
149 assertEquals( null, expecteds, actuals );
150 }
151
152
153
154
155
156
157
158 public static void assertEquals( int[] expecteds, Object[] actuals )
159 {
160 assertEquals( null, expecteds, actuals );
161 }
162
163
164
165
166
167
168
169 public static void assertEquals( List expecteds, List actuals )
170 {
171 assertEquals( null, expecteds, actuals );
172 }
173
174
175
176
177
178
179
180 public static void assertEquals( long[] expecteds, long[] actuals )
181 {
182 assertEquals( null, expecteds, actuals );
183 }
184
185
186
187
188
189
190
191 public static void assertEquals( long[] expecteds, Object[] actuals )
192 {
193 assertEquals( null, expecteds, actuals );
194 }
195
196
197
198
199
200
201
202
203 public static void assertEquals( Object expected, Object actual )
204 {
205 assertEquals( null, expected, actual );
206 }
207
208
209
210
211
212
213
214 public static void assertEquals( Object[] expecteds, boolean[] actuals )
215 {
216 assertEquals( null, expecteds, actuals );
217 }
218
219
220
221
222
223
224
225 public static void assertEquals( Object[] expecteds, byte[] actuals )
226 {
227 assertEquals( null, expecteds, actuals );
228 }
229
230
231
232
233
234
235
236 public static void assertEquals( Object[] expecteds, char[] actuals )
237 {
238 assertEquals( null, expecteds, actuals );
239 }
240
241
242
243
244
245
246
247 public static void assertEquals( Object[] expecteds, double[] actuals )
248 {
249 assertEquals( null, expecteds, actuals );
250 }
251
252
253
254
255
256
257
258 public static void assertEquals( Object[] expecteds, float[] actuals )
259 {
260 assertEquals( null, expecteds, actuals );
261 }
262
263
264
265
266
267
268
269 public static void assertEquals( Object[] expecteds, int[] actuals )
270 {
271 assertEquals( null, expecteds, actuals );
272 }
273
274
275
276
277
278
279
280 public static void assertEquals( Object[] expecteds, long[] actuals )
281 {
282 assertEquals( null, expecteds, actuals );
283 }
284
285
286
287
288
289
290
291 public static void assertEquals( Object[] expecteds, Object[] actuals )
292 {
293 assertEquals( null, expecteds, actuals );
294 }
295
296
297
298
299
300
301
302 public static void assertEquals( Object[] expecteds, short[] actuals )
303 {
304 assertEquals( null, expecteds, actuals );
305 }
306
307
308
309
310
311
312
313 public static void assertEquals( short[] expecteds, Object[] actuals )
314 {
315 assertEquals( null, expecteds, actuals );
316 }
317
318
319
320
321
322
323
324 public static void assertEquals( short[] expecteds, short[] actuals )
325 {
326 assertEquals( null, expecteds, actuals );
327 }
328
329
330
331
332
333
334
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
361
362
363
364
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
388
389
390
391
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
418
419
420
421
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
445
446
447
448
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
475
476
477
478
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
502
503
504
505
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
532
533
534
535
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
559
560
561
562
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
589
590
591
592
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
616
617
618
619
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
646
647
648
649
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
673
674
675
676
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
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
731
732
733
734
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
761
762
763
764
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
788
789
790
791
792
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
821
822
823
824
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
848
849
850
851
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
875
876
877
878
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
902
903
904
905
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
929
930
931
932
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
956
957
958
959
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
983
984
985
986
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
1010
1011
1012
1013
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
1161
1162
1163
1164
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
1188
1189
1190
1191
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
1215
1216
1217
1218
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 }