1 package junitx.framework; 2 3 import junit.framework.AssertionFailedError; 4 import junit.framework.TestCase; 5 import junitx.example.PrivateAccessorExample; 6 7 11 public class ObjectAssertTest 12 extends TestCase { 13 14 public ObjectAssertTest(String 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 (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 (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 obj = new Integer (1); 46 ObjectAssert.assertSame(obj, obj); 47 } 48 49 public void testFailSame() { 50 try { 51 ObjectAssert.assertSame(new Integer (1), new Integer (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 (1), new Integer (1)); 60 } 61 62 public void testFailNotSame() { 63 try { 64 Object obj = new Integer (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 |