KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > ObjectAssertTest


1 package junitx.framework;
2
3 import junit.framework.AssertionFailedError;
4 import junit.framework.TestCase;
5 import junitx.example.PrivateAccessorExample;
6
7 /**
8  * @version $Revision: 1.3 $ $Date: 2003/04/27 02:14:59 $
9  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
10  */

11 public class ObjectAssertTest
12         extends TestCase {
13
14     public ObjectAssertTest(String JavaDoc name) {
15         super(name);
16     }
17
18     public void testSuccessInstanceOf() {
19         ObjectAssert.assertInstanceOf(PrivateAccessorExample.class, new PrivateAccessorExample());
20     }
21
22     public void testFailInstanceOf() {
23         try {
24             ObjectAssert.assertInstanceOf(PrivateAccessorExample.class, new Integer JavaDoc(1));
25         } catch (AssertionFailedError e) {
26             return;
27         }
28         fail("Should have thrown exception");
29     }
30
31     public void testSuccessNotInstanceOf() {
32         ObjectAssert.assertNotInstanceOf(PrivateAccessorExample.class, new Integer JavaDoc(1));
33     }
34
35     public void testFailNotInstanceOf() {
36         try {
37             ObjectAssert.assertNotInstanceOf(PrivateAccessorExample.class, new PrivateAccessorExample());
38         } catch (AssertionFailedError e) {
39             return;
40         }
41         fail("Should have thrown exception");
42     }
43
44     public void testSuccessSame() {
45         Object JavaDoc obj = new Integer JavaDoc(1);
46         ObjectAssert.assertSame(obj, obj);
47     }
48     
49     public void testFailSame() {
50         try {
51             ObjectAssert.assertSame(new Integer JavaDoc(1), new Integer JavaDoc(1));
52         } catch (AssertionFailedError e) {
53             return;
54         }
55         fail("Should have thrown exception");
56     }
57     
58     public void testSuccessNotSame() {
59         ObjectAssert.assertNotSame(new Integer JavaDoc(1), new Integer JavaDoc(1));
60     }
61     
62     public void testFailNotSame() {
63         try {
64             Object JavaDoc obj = new Integer JavaDoc(1);
65             ObjectAssert.assertNotSame(obj, obj);
66         } catch (AssertionFailedError e) {
67             return;
68         }
69         fail("Should have thrown exception");
70     }
71     
72 }
73
Popular Tags