1   package org.apache.maven.surefire.assertion;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  /**
25   * Test the surefire assertion class.
26   *
27   * @noinspection ProhibitedExceptionCaught
28   */
29  public class SurefireAssertTest
30      extends TestCase
31  {
32      public void testFailWithNoMessage()
33      {
34          try
35          {
36              SurefireAssert.fail( (String) null );
37              fail( "Should have thrown a NullPointerException" );
38          }
39          catch ( NullPointerException e )
40          {
41              // expected
42          }
43      }
44  
45      public void testFailWithNoCause()
46      {
47          try
48          {
49              SurefireAssert.fail( (Throwable) null );
50              fail( "Should have thrown a NullPointerException" );
51          }
52          catch ( NullPointerException e )
53          {
54              // expected
55          }
56      }
57  
58  
59      public void testFailWithMessageButNoCause()
60      {
61          try
62          {
63              SurefireAssert.fail( "msg", null );
64              fail( "Should have thrown a NullPointerException" );
65          }
66          catch ( NullPointerException e )
67          {
68              // expected
69          }
70      }
71  
72      public void testFailWithCauseButNoMessage()
73      {
74          try
75          {
76              SurefireAssert.fail( null, new Exception( "msg" ) );
77              fail( "Should have thrown a NullPointerException" );
78          }
79          catch ( NullPointerException e )
80          {
81              // expected
82          }
83      }
84  
85      public void testFailWithNoMessageOrCause()
86      {
87          try
88          {
89              SurefireAssert.fail();
90              fail( "Should have failed" );
91          }
92          catch ( SurefireAssertionFailedException e )
93          {
94              // expected
95              assertNull( e.getMessage() );
96          }
97      }
98  
99      public void testFailWithMessage()
100     {
101         try
102         {
103             SurefireAssert.fail( "msg" );
104             fail( "Should have failed" );
105         }
106         catch ( SurefireAssertionFailedException e )
107         {
108             // expected
109             assertEquals( "msg", e.getMessage() );
110         }
111     }
112 
113     public void testFailWithCause()
114     {
115         try
116         {
117             SurefireAssert.fail( new Exception( "nestedMsg" ) );
118             fail( "Should have failed" );
119         }
120         catch ( SurefireAssertionFailedException e )
121         {
122             // expected
123             assertEquals( "null; nested exception is java.lang.Exception: nestedMsg", e.getMessage() );
124             assertEquals( "nestedMsg", e.getCause().getMessage() );
125         }
126     }
127 
128     public void testFailWithMessageAndCause()
129     {
130         try
131         {
132             SurefireAssert.fail( "msg", new Exception( "nestedMsg" ) );
133             fail( "Should have failed" );
134         }
135         catch ( SurefireAssertionFailedException e )
136         {
137             // expected
138             assertEquals( "msg; nested exception is java.lang.Exception: nestedMsg", e.getMessage() );
139             assertEquals( "nestedMsg", e.getCause().getMessage() );
140         }
141     }
142 
143     public void testFailAssertTrueWithMessage()
144     {
145         try
146         {
147             SurefireAssert.assertTrue( "msg", false );
148             fail( "Should have failed" );
149         }
150         catch ( SurefireAssertionFailedException e )
151         {
152             // expected
153             assertEquals( "msg", e.getMessage() );
154         }
155     }
156 
157     public void testPassAssertTrueWithMessage()
158     {
159         SurefireAssert.assertTrue( "msg", true );
160     }
161 
162     public void testFailAssertTrueWithoutMessage()
163     {
164         try
165         {
166             SurefireAssert.assertTrue( false );
167             fail( "Should have failed" );
168         }
169         catch ( SurefireAssertionFailedException e )
170         {
171             // expected
172             assertNull( e.getMessage() );
173         }
174     }
175 
176     public void testPassAssertTrueWithoutMessage()
177     {
178         SurefireAssert.assertTrue( true );
179     }
180 
181     public void testFailAssertFalseWithMessage()
182     {
183         try
184         {
185             SurefireAssert.assertFalse( "msg", true );
186             fail( "Should have failed" );
187         }
188         catch ( SurefireAssertionFailedException e )
189         {
190             // expected
191             assertEquals( "msg", e.getMessage() );
192         }
193     }
194 
195     public void testPassAssertFalseWithMessage()
196     {
197         SurefireAssert.assertFalse( "msg", false );
198     }
199 
200     public void testFailAssertFalseWithoutMessage()
201     {
202         try
203         {
204             SurefireAssert.assertFalse( true );
205             fail( "Should have failed" );
206         }
207         catch ( SurefireAssertionFailedException e )
208         {
209             // expected
210             assertNull( e.getMessage() );
211         }
212     }
213 
214     public void testPassAssertFalseWithoutMessage()
215     {
216         SurefireAssert.assertFalse( false );
217     }
218 
219     public void testFailAssertEqualsStringWithMessage()
220     {
221         try
222         {
223             SurefireAssert.assertEquals( "msg", "foo", "bar" );
224             fail( "Should have failed" );
225         }
226         catch ( SurefireAssertionFailedException e )
227         {
228             // expected
229             assertEquals( "msg expected:<foo> but was:<bar>", e.getMessage() );
230         }
231     }
232 
233     public void testFailAssertEqualsStringExpectedNullWithMessage()
234     {
235         try
236         {
237             SurefireAssert.assertEquals( "msg", null, "bar" );
238             fail( "Should have failed" );
239         }
240         catch ( SurefireAssertionFailedException e )
241         {
242             // expected
243             assertEquals( "msg expected:<null> but was:<bar>", e.getMessage() );
244         }
245     }
246 
247     public void testFailAssertEqualsStringActualNullWithMessage()
248     {
249         try
250         {
251             SurefireAssert.assertEquals( "msg", "foo", null );
252             fail( "Should have failed" );
253         }
254         catch ( SurefireAssertionFailedException e )
255         {
256             // expected
257             assertEquals( "msg expected:<foo> but was:<null>", e.getMessage() );
258         }
259     }
260 
261     public void testPassAssertEqualsStringWithMessage()
262     {
263         SurefireAssert.assertEquals( "msg", "foo", "foo" );
264     }
265 
266     public void testPassAssertEqualsStringBothNullWithMessage()
267     {
268         SurefireAssert.assertEquals( "msg", null, null );
269     }
270 
271     public void testPassAssertEqualsStringWithoutMessage()
272     {
273         SurefireAssert.assertEquals( "foo", "foo" );
274     }
275 
276     public void testFailAssertEqualsStringWithoutMessage()
277     {
278         try
279         {
280             SurefireAssert.assertEquals( "foo", "bar" );
281             fail( "Should have failed" );
282         }
283         catch ( SurefireAssertionFailedException e )
284         {
285             // expected
286             assertEquals( "expected:<foo> but was:<bar>", e.getMessage() );
287         }
288     }
289 
290     public void testFailAssertEqualsObjectWithMessage()
291     {
292         try
293         {
294             SurefireAssert.assertEquals( "msg", new DummyObject( "foo" ), new DummyObject( "bar" ) );
295             fail( "Should have failed" );
296         }
297         catch ( SurefireAssertionFailedException e )
298         {
299             // expected
300             assertEquals( "msg expected:<foo> but was:<bar>", e.getMessage() );
301         }
302     }
303 
304     public void testFailAssertEqualsObjectDoesntTrim()
305     {
306         try
307         {
308             SurefireAssert.assertEquals( "msg", new DummyObject( "foo" ), new DummyObject( "fobar" ) );
309             fail( "Should have failed" );
310         }
311         catch ( SurefireAssertionFailedException e )
312         {
313             // expected
314             assertEquals( "msg expected:<foo> but was:<fobar>", e.getMessage() );
315         }
316     }
317 
318     public void testFailAssertEqualsObjectExpectedNullWithMessage()
319     {
320         try
321         {
322             SurefireAssert.assertEquals( "msg", null, new DummyObject( "bar" ) );
323             fail( "Should have failed" );
324         }
325         catch ( SurefireAssertionFailedException e )
326         {
327             // expected
328             assertEquals( "msg expected:<null> but was:<bar>", e.getMessage() );
329         }
330     }
331 
332     public void testFailAssertEqualsObjectActualNullWithMessage()
333     {
334         try
335         {
336             SurefireAssert.assertEquals( "msg", new DummyObject( "foo" ), null );
337             fail( "Should have failed" );
338         }
339         catch ( SurefireAssertionFailedException e )
340         {
341             // expected
342             assertEquals( "msg expected:<foo> but was:<null>", e.getMessage() );
343         }
344     }
345 
346     public void testPassAssertEqualsObjectWithMessage()
347     {
348         SurefireAssert.assertEquals( "msg", new DummyObject( "foo" ), new DummyObject( "foo" ) );
349     }
350 
351     public void testPassAssertEqualsObjectBothNullWithMessage()
352     {
353         SurefireAssert.assertEquals( "msg", null, null );
354     }
355 
356     public void testPassAssertEqualsObjectWithoutMessage()
357     {
358         SurefireAssert.assertEquals( new DummyObject( "foo" ), new DummyObject( "foo" ) );
359     }
360 
361     public void testFailAssertEqualsObjectWithoutMessage()
362     {
363         try
364         {
365             SurefireAssert.assertEquals( new DummyObject( "foo" ), new DummyObject( "bar" ) );
366             fail( "Should have failed" );
367         }
368         catch ( SurefireAssertionFailedException e )
369         {
370             // expected
371             assertEquals( "expected:<foo> but was:<bar>", e.getMessage() );
372         }
373     }
374 
375     public void testFailAssertEqualsIntWithMessage()
376     {
377         try
378         {
379             SurefireAssert.assertEquals( "msg", 1, 2 );
380             fail( "Should have failed" );
381         }
382         catch ( SurefireAssertionFailedException e )
383         {
384             // expected
385             assertEquals( "msg expected:<1> but was:<2>", e.getMessage() );
386         }
387     }
388 
389     public void testPassAssertEqualsIntWithMessage()
390     {
391         SurefireAssert.assertEquals( "msg", 1, 1 );
392     }
393 
394     public void testPassAssertEqualsIntWithoutMessage()
395     {
396         SurefireAssert.assertEquals( 1, 1 );
397     }
398 
399     public void testFailAssertEqualsIntWithoutMessage()
400     {
401         try
402         {
403             SurefireAssert.assertEquals( 1, 2 );
404             fail( "Should have failed" );
405         }
406         catch ( SurefireAssertionFailedException e )
407         {
408             // expected
409             assertEquals( "expected:<1> but was:<2>", e.getMessage() );
410         }
411     }
412 
413     public void testFailAssertEqualsLongWithMessage()
414     {
415         try
416         {
417             SurefireAssert.assertEquals( "msg", 1L, 2L );
418             fail( "Should have failed" );
419         }
420         catch ( SurefireAssertionFailedException e )
421         {
422             // expected
423             assertEquals( "msg expected:<1> but was:<2>", e.getMessage() );
424         }
425     }
426 
427     public void testPassAssertEqualsLongWithMessage()
428     {
429         SurefireAssert.assertEquals( "msg", 1L, 1L );
430     }
431 
432     public void testPassAssertEqualsLongWithoutMessage()
433     {
434         SurefireAssert.assertEquals( 1L, 1L );
435     }
436 
437     public void testFailAssertEqualsLongWithoutMessage()
438     {
439         try
440         {
441             SurefireAssert.assertEquals( 1L, 2L );
442             fail( "Should have failed" );
443         }
444         catch ( SurefireAssertionFailedException e )
445         {
446             // expected
447             assertEquals( "expected:<1> but was:<2>", e.getMessage() );
448         }
449     }
450 
451     public void testFailAssertEqualsFloatWithMessage()
452     {
453         try
454         {
455             SurefireAssert.assertEquals( "msg", 1.2f, 3.4f, 0.1f );
456             fail( "Should have failed" );
457         }
458         catch ( SurefireAssertionFailedException e )
459         {
460             // expected
461             assertEquals( "msg expected:<1.2> but was:<3.4>", e.getMessage() );
462         }
463     }
464 
465     public void testPassAssertEqualsFloatWithMessage()
466     {
467         SurefireAssert.assertEquals( "msg", 1.2f, 1.2f, 0.1f );
468     }
469 
470     public void testPassAssertEqualsFloatWithoutMessage()
471     {
472         SurefireAssert.assertEquals( 1.2f, 1.2f, 0.1f );
473     }
474 
475     public void testFailAssertEqualsFloatWithoutMessage()
476     {
477         try
478         {
479             SurefireAssert.assertEquals( 1.2f, 3.4f, 0.1f );
480             fail( "Should have failed" );
481         }
482         catch ( SurefireAssertionFailedException e )
483         {
484             // expected
485             assertEquals( "expected:<1.2> but was:<3.4>", e.getMessage() );
486         }
487     }
488 
489     public void testPassAssertEqualsFloatWithFudge()
490     {
491         SurefireAssert.assertEquals( 1.2f, 1.3f, 0.5f );
492     }
493 
494     public void testFailAssertEqualsFloatWithoutFudge()
495     {
496         try
497         {
498             SurefireAssert.assertEquals( 1.2f, 1.3f, 0.05f );
499             fail( "Should have failed" );
500         }
501         catch ( SurefireAssertionFailedException e )
502         {
503             // expected
504             assertEquals( "expected:<1.2> but was:<1.3>", e.getMessage() );
505         }
506     }
507 
508     public void testFailAssertEqualsFloatExpectedIsInfinite()
509     {
510         try
511         {
512             SurefireAssert.assertEquals( Float.POSITIVE_INFINITY, 1.3f, 0.05f );
513             fail( "Should have failed" );
514         }
515         catch ( SurefireAssertionFailedException e )
516         {
517             // expected
518             assertEquals( "expected:<Infinity> but was:<1.3>", e.getMessage() );
519         }
520     }
521 
522     public void testFailAssertEqualsFloatActualIsInfinite()
523     {
524         try
525         {
526             SurefireAssert.assertEquals( 1.2f, Float.POSITIVE_INFINITY, 0.05f );
527             fail( "Should have failed" );
528         }
529         catch ( SurefireAssertionFailedException e )
530         {
531             // expected
532             assertEquals( "expected:<1.2> but was:<Infinity>", e.getMessage() );
533         }
534     }
535 
536     public void testPassAssertEqualsFloatBothAreInfinite()
537     {
538         SurefireAssert.assertEquals( Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, 0.05f );
539     }
540 
541     public void testFailAssertEqualsDoubleWithMessage()
542     {
543         try
544         {
545             SurefireAssert.assertEquals( "msg", 1.2, 3.4, 0.1 );
546             fail( "Should have failed" );
547         }
548         catch ( SurefireAssertionFailedException e )
549         {
550             // expected
551             assertEquals( "msg expected:<1.2> but was:<3.4>", e.getMessage() );
552         }
553     }
554 
555     public void testPassAssertEqualsDoubleWithMessage()
556     {
557         SurefireAssert.assertEquals( "msg", 1.2, 1.2, 0.1 );
558     }
559 
560     public void testPassAssertEqualsDoubleWithoutMessage()
561     {
562         SurefireAssert.assertEquals( 1.2, 1.2, 0.1 );
563     }
564 
565     public void testFailAssertEqualsDoubleWithoutMessage()
566     {
567         try
568         {
569             SurefireAssert.assertEquals( 1.2, 3.4, 0.1 );
570             fail( "Should have failed" );
571         }
572         catch ( SurefireAssertionFailedException e )
573         {
574             // expected
575             assertEquals( "expected:<1.2> but was:<3.4>", e.getMessage() );
576         }
577     }
578 
579     public void testPassAssertEqualsDoubleWithFudge()
580     {
581         SurefireAssert.assertEquals( 1.2, 1.3, 0.5 );
582     }
583 
584     public void testFailAssertEqualsDoubleWithoutFudge()
585     {
586         try
587         {
588             SurefireAssert.assertEquals( 1.2, 1.3, 0.05 );
589             fail( "Should have failed" );
590         }
591         catch ( SurefireAssertionFailedException e )
592         {
593             // expected
594             assertEquals( "expected:<1.2> but was:<1.3>", e.getMessage() );
595         }
596     }
597 
598     public void testFailAssertEqualsDoubleExpectedIsInfinite()
599     {
600         try
601         {
602             SurefireAssert.assertEquals( Double.POSITIVE_INFINITY, 1.3, 0.05 );
603             fail( "Should have failed" );
604         }
605         catch ( SurefireAssertionFailedException e )
606         {
607             // expected
608             assertEquals( "expected:<Infinity> but was:<1.3>", e.getMessage() );
609         }
610     }
611 
612     public void testFailAssertEqualsDoubleActualIsInfinite()
613     {
614         try
615         {
616             SurefireAssert.assertEquals( 1.2, Double.POSITIVE_INFINITY, 0.05 );
617             fail( "Should have failed" );
618         }
619         catch ( SurefireAssertionFailedException e )
620         {
621             // expected
622             assertEquals( "expected:<1.2> but was:<Infinity>", e.getMessage() );
623         }
624     }
625 
626     public void testPassAssertEqualsDoubleBothAreInfinite()
627     {
628         SurefireAssert.assertEquals( Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0.05 );
629     }
630 
631     public void testFailAssertEqualsByteWithMessage()
632     {
633         try
634         {
635             SurefireAssert.assertEquals( "msg", (byte) 1, (byte) 2 );
636             fail( "Should have failed" );
637         }
638         catch ( SurefireAssertionFailedException e )
639         {
640             // expected
641             assertEquals( "msg expected:<1> but was:<2>", e.getMessage() );
642         }
643     }
644 
645     public void testPassAssertEqualsByteWithMessage()
646     {
647         SurefireAssert.assertEquals( "msg", (byte) 1, (byte) 1 );
648     }
649 
650     public void testPassAssertEqualsByteWithoutMessage()
651     {
652         SurefireAssert.assertEquals( (byte) 1, (byte) 1 );
653     }
654 
655     public void testFailAssertEqualsByteWithoutMessage()
656     {
657         try
658         {
659             SurefireAssert.assertEquals( (byte) 1, (byte) 2 );
660             fail( "Should have failed" );
661         }
662         catch ( SurefireAssertionFailedException e )
663         {
664             // expected
665             assertEquals( "expected:<1> but was:<2>", e.getMessage() );
666         }
667     }
668 
669     public void testFailAssertEqualsBooleanWithMessage()
670     {
671         try
672         {
673             SurefireAssert.assertEquals( "msg", true, false );
674             fail( "Should have failed" );
675         }
676         catch ( SurefireAssertionFailedException e )
677         {
678             // expected
679             assertEquals( "msg expected:<true> but was:<false>", e.getMessage() );
680         }
681         try
682         {
683             SurefireAssert.assertEquals( "msg", false, true );
684             fail( "Should have failed" );
685         }
686         catch ( SurefireAssertionFailedException e )
687         {
688             // expected
689             assertEquals( "msg expected:<false> but was:<true>", e.getMessage() );
690         }
691     }
692 
693     public void testPassAssertEqualsBooleanWithMessage()
694     {
695         SurefireAssert.assertEquals( "msg", true, true );
696         SurefireAssert.assertEquals( "msg", false, false );
697     }
698 
699     public void testPassAssertEqualsBooleanWithoutMessage()
700     {
701         SurefireAssert.assertEquals( true, true );
702         SurefireAssert.assertEquals( false, false );
703     }
704 
705     public void testFailAssertEqualsBooleanWithoutMessage()
706     {
707         try
708         {
709             SurefireAssert.assertEquals( true, false );
710             fail( "Should have failed" );
711         }
712         catch ( SurefireAssertionFailedException e )
713         {
714             // expected
715             assertEquals( "expected:<true> but was:<false>", e.getMessage() );
716         }
717         try
718         {
719             SurefireAssert.assertEquals( false, true );
720             fail( "Should have failed" );
721         }
722         catch ( SurefireAssertionFailedException e )
723         {
724             // expected
725             assertEquals( "expected:<false> but was:<true>", e.getMessage() );
726         }
727     }
728 
729     public void testFailAssertEqualsCharWithMessage()
730     {
731         try
732         {
733             SurefireAssert.assertEquals( "msg", '1', '2' );
734             fail( "Should have failed" );
735         }
736         catch ( SurefireAssertionFailedException e )
737         {
738             // expected
739             assertEquals( "msg expected:<1> but was:<2>", e.getMessage() );
740         }
741     }
742 
743     public void testPassAssertEqualsCharWithMessage()
744     {
745         SurefireAssert.assertEquals( "msg", '1', '1' );
746     }
747 
748     public void testPassAssertEqualsCharWithoutMessage()
749     {
750         SurefireAssert.assertEquals( '1', '1' );
751     }
752 
753     public void testFailAssertEqualsCharWithoutMessage()
754     {
755         try
756         {
757             SurefireAssert.assertEquals( '1', '2' );
758             fail( "Should have failed" );
759         }
760         catch ( SurefireAssertionFailedException e )
761         {
762             // expected
763             assertEquals( "expected:<1> but was:<2>", e.getMessage() );
764         }
765     }
766 
767     public void testFailAssertEqualsShortWithMessage()
768     {
769         try
770         {
771             SurefireAssert.assertEquals( "msg", (short) 1, (short) 2 );
772             fail( "Should have failed" );
773         }
774         catch ( SurefireAssertionFailedException e )
775         {
776             // expected
777             assertEquals( "msg expected:<1> but was:<2>", e.getMessage() );
778         }
779     }
780 
781     public void testPassAssertEqualsShortWithMessage()
782     {
783         SurefireAssert.assertEquals( "msg", (short) 1, (short) 1 );
784     }
785 
786     public void testPassAssertEqualsShortWithoutMessage()
787     {
788         SurefireAssert.assertEquals( (short) 1, (short) 1 );
789     }
790 
791     public void testFailAssertEqualsShortWithoutMessage()
792     {
793         try
794         {
795             SurefireAssert.assertEquals( (short) 1, (short) 2 );
796             fail( "Should have failed" );
797         }
798         catch ( SurefireAssertionFailedException e )
799         {
800             // expected
801             assertEquals( "expected:<1> but was:<2>", e.getMessage() );
802         }
803     }
804 
805     public void testFailAssertNullWithMessage()
806     {
807         try
808         {
809             SurefireAssert.assertNull( "msg", new DummyObject( "foo" ) );
810             fail( "Should have failed" );
811         }
812         catch ( SurefireAssertionFailedException e )
813         {
814             // expected
815             assertEquals( "msg", e.getMessage() );
816         }
817     }
818 
819     public void testPassAssertNullWithMessage()
820     {
821         SurefireAssert.assertNull( "msg", null );
822     }
823 
824     public void testFailAssertNullWithoutMessage()
825     {
826         try
827         {
828             SurefireAssert.assertNull( new DummyObject( "foo" ) );
829             fail( "Should have failed" );
830         }
831         catch ( SurefireAssertionFailedException e )
832         {
833             // expected
834             assertNull( e.getMessage() );
835         }
836     }
837 
838     public void testPassAssertNullWithoutMessage()
839     {
840         SurefireAssert.assertNull( null );
841     }
842 
843     public void testFailAssertNotNullWithMessage()
844     {
845         try
846         {
847             SurefireAssert.assertNotNull( "msg", null );
848             fail( "Should have failed" );
849         }
850         catch ( SurefireAssertionFailedException e )
851         {
852             // expected
853             assertEquals( "msg", e.getMessage() );
854         }
855     }
856 
857     public void testPassAssertNotNullWithMessage()
858     {
859         SurefireAssert.assertNotNull( "msg", new DummyObject( "foo" ) );
860     }
861 
862     public void testFailAssertNotNullWithoutMessage()
863     {
864         try
865         {
866             SurefireAssert.assertNotNull( null );
867             fail( "Should have failed" );
868         }
869         catch ( SurefireAssertionFailedException e )
870         {
871             // expected
872             assertNull( e.getMessage() );
873         }
874     }
875 
876     public void testPassAssertNotNullWithoutMessage()
877     {
878         SurefireAssert.assertNotNull( new DummyObject( "foo" ) );
879     }
880 
881     public void testFailAssertSameWithMessage()
882     {
883         try
884         {
885             SurefireAssert.assertSame( "msg", new DummyObject( "foo" ), new DummyObject( "foo" ) );
886             fail( "Should have failed" );
887         }
888         catch ( SurefireAssertionFailedException e )
889         {
890             // expected
891             assertEquals( "msg expected same:<foo> was not:<foo>", e.getMessage() );
892         }
893     }
894 
895     public void testFailAssertSameDoesntTrim()
896     {
897         try
898         {
899             SurefireAssert.assertSame( "msg", new DummyObject( "foo" ), new DummyObject( "fobar" ) );
900             fail( "Should have failed" );
901         }
902         catch ( SurefireAssertionFailedException e )
903         {
904             // expected
905             assertEquals( "msg expected same:<foo> was not:<fobar>", e.getMessage() );
906         }
907     }
908 
909     public void testFailAssertSameExpectedNullWithMessage()
910     {
911         try
912         {
913             SurefireAssert.assertSame( "msg", null, new DummyObject( "bar" ) );
914             fail( "Should have failed" );
915         }
916         catch ( SurefireAssertionFailedException e )
917         {
918             // expected
919             assertEquals( "msg expected same:<null> was not:<bar>", e.getMessage() );
920         }
921     }
922 
923     public void testFailAssertSameActualNullWithMessage()
924     {
925         try
926         {
927             SurefireAssert.assertSame( "msg", new DummyObject( "foo" ), null );
928             fail( "Should have failed" );
929         }
930         catch ( SurefireAssertionFailedException e )
931         {
932             // expected
933             assertEquals( "msg expected same:<foo> was not:<null>", e.getMessage() );
934         }
935     }
936 
937     public void testPassAssertSameWithMessage()
938     {
939         DummyObject value = new DummyObject( "foo" );
940         SurefireAssert.assertSame( "msg", value, value );
941     }
942 
943     public void testPassAssertSameBothNullWithMessage()
944     {
945         SurefireAssert.assertSame( "msg", null, null );
946     }
947 
948     public void testPassAssertSameWithoutMessage()
949     {
950         DummyObject value = new DummyObject( "foo" );
951         SurefireAssert.assertSame( value, value );
952     }
953 
954     public void testFailAssertSameWithoutMessage()
955     {
956         try
957         {
958             SurefireAssert.assertSame( new DummyObject( "foo" ), new DummyObject( "foo" ) );
959             fail( "Should have failed" );
960         }
961         catch ( SurefireAssertionFailedException e )
962         {
963             // expected
964             assertEquals( "expected same:<foo> was not:<foo>", e.getMessage() );
965         }
966     }
967 
968     public void testFailAssertNotSameWithMessage()
969     {
970         try
971         {
972             DummyObject value = new DummyObject( "foo" );
973             SurefireAssert.assertNotSame( "msg", value, value );
974             fail( "Should have failed" );
975         }
976         catch ( SurefireAssertionFailedException e )
977         {
978             // expected
979             assertEquals( "msg expected not same", e.getMessage() );
980         }
981     }
982 
983     public void testFailAssertNotSameExpectedNullWithMessage()
984     {
985         SurefireAssert.assertNotSame( "msg", null, new DummyObject( "bar" ) );
986     }
987 
988     public void testFailAssertNotSameActualNullWithMessage()
989     {
990         SurefireAssert.assertNotSame( "msg", new DummyObject( "foo" ), null );
991     }
992 
993     public void testPassAssertNotSameWithMessage()
994     {
995         SurefireAssert.assertNotSame( "msg", new DummyObject( "foo" ), new DummyObject( "foo" ) );
996     }
997 
998     public void testPassAssertNotSameBothNullWithMessage()
999     {
1000         try
1001         {
1002             SurefireAssert.assertNotSame( "msg", null, null );
1003             fail( "Should not be the same" );
1004         }
1005         catch ( SurefireAssertionFailedException e )
1006         {
1007             // expected
1008             assertEquals( "msg expected not same", e.getMessage() );
1009         }
1010     }
1011 
1012     public void testPassAssertNotSameWithoutMessage()
1013     {
1014         SurefireAssert.assertNotSame( new DummyObject( "foo" ), new DummyObject( "foo" ) );
1015     }
1016 
1017     public void testFailAssertNotSameWithoutMessage()
1018     {
1019         try
1020         {
1021             DummyObject value = new DummyObject( "foo" );
1022             SurefireAssert.assertNotSame( value, value );
1023             fail( "Should have failed" );
1024         }
1025         catch ( SurefireAssertionFailedException e )
1026         {
1027             // expected
1028             assertEquals( "expected not same", e.getMessage() );
1029         }
1030     }
1031 
1032     private static class DummyObject
1033     {
1034         private final String value;
1035 
1036         private DummyObject( String value )
1037         {
1038             this.value = value;
1039         }
1040 
1041         public boolean equals( Object obj )
1042         {
1043             if ( this == obj )
1044             {
1045                 return true;
1046             }
1047             if ( obj == null || getClass() != obj.getClass() )
1048             {
1049                 return false;
1050             }
1051 
1052             DummyObject that = (DummyObject) obj;
1053 
1054             return !( value != null ? !value.equals( that.value ) : that.value != null );
1055 
1056         }
1057 
1058         public int hashCode()
1059         {
1060             return value != null ? value.hashCode() : 0;
1061         }
1062 
1063         public String toString()
1064         {
1065             return value;
1066         }
1067     }
1068 }