1 package junitx.framework; 2 3 import junit.framework.AssertionFailedError; 4 import junit.framework.TestCase; 5 6 10 public class AssertTest 11 extends TestCase { 12 13 public AssertTest(String name) { 14 super(name); 15 } 16 17 public void testSuccessAssertFalse() { 18 Assert.assertFalse(false); 19 } 20 21 public void testFailAssertFalse() 22 throws Exception { 23 try { 24 Assert.assertFalse(true); 25 } catch (AssertionFailedError e) { 26 return; 27 } 28 fail("Should have thrown exception"); 29 } 30 31 public void testSucceedAssertNotEquals() 32 throws Exception { 33 Assert.assertNotEquals(new Integer (1), new Integer (2)); 34 } 35 36 public void testSucceedAssertNotEqualsNullExpected() 37 throws Exception { 38 Assert.assertNotEquals(null, new Integer (2)); 39 } 40 41 public void testSucceedAssertNotEqualsNullActual() 42 throws Exception { 43 Assert.assertNotEquals(new Integer (1), null); 44 } 45 46 public void testFailAssertNotEquals() 47 throws Exception { 48 try { 49 Assert.assertNotEquals(new Integer (2), new Integer (2)); 50 } catch (AssertionFailedError e) { 51 return; 52 } 53 fail("Should have thrown exception"); 54 } 55 56 public void testFailAssertNotEqualsNulls() 57 throws Exception { 58 try { 59 Assert.assertNotEquals(null, null); 60 } catch (AssertionFailedError e) { 61 return; 62 } 63 fail("Should have thrown exception"); 64 } 65 66 public void testSucceedAssertNotEqualsFloat() { 67 Assert.assertNotEquals(1.0d, 2.0d, 0.5d); 68 } 69 70 public void testFailAssertNotEqualsFloat() { 71 try { 72 Assert.assertNotEquals(1.0d, 1.5d, 1.0d); 73 } catch (AssertionFailedError e) { 74 return; 75 } 76 fail("Should have thrown exception"); 77 } 78 79 public void testSucceedNotSame() { 80 Assert.assertNotSame(new Integer (1), new Integer (1)); 81 } 82 83 public void testFailNotSame() { 84 try { 85 Integer integer = new Integer (1); 86 Assert.assertNotSame(integer, integer); 87 } catch (AssertionFailedError e) { 88 return; 89 } 90 fail("Should have thrown exception"); 91 } 92 93 public void testFailThrowable() { 94 try { 95 Assert.fail(new NullPointerException ("dummy")); 96 } catch (AssertionFailedError e) { 97 return; 98 } 99 fail("Should have thrown exception"); 100 } 101 102 } 103 | Popular Tags |