1 package net.firstpartners.nounit.utility.test; 2 3 26 27 import junit.framework.Test; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 import net.firstpartners.nounit.utility.NoUnitException; 31 32 35 public class TestNoUnitException extends TestCase { 36 37 41 public TestNoUnitException(String name) { 42 super(name); 43 } 44 45 48 protected void setUp() 49 { 50 52 } 53 54 58 public static void main(String [] args) { 59 junit.textui.TestRunner.run (suite()); 60 } 61 62 66 public static Test suite() { 67 return new TestSuite(TestNoUnitException.class); 68 } 69 70 73 public void testException1Value() 74 { 75 76 try { 77 if (true) 79 throw new NoUnitException("SomeUserMessage"); 80 81 fail("Expected Exception Not thrown"); 82 } 83 catch (Exception e) 84 { 85 assertTrue(e instanceof Exception ); 87 assertTrue(e instanceof NoUnitException); 88 assertTrue(e.toString()!=null); 89 assertTrue(e.toString().indexOf("omeUserMessage")>0); 90 91 NoUnitException myException =(NoUnitException)e; 92 assertTrue(myException.getUserErrorMessage().equals("SomeUserMessage")); 93 } 94 95 } 96 97 100 public void testException2Values() 101 { 102 103 try { 104 if (true) 106 throw new NoUnitException("TestKey","TestValue"); 107 108 fail("Expected Exception Not thrown"); 109 } 110 catch (Exception e) 111 { 112 assertTrue(e instanceof Exception ); 114 assertTrue(e instanceof NoUnitException); 115 assertTrue(e.toString()!=null); 116 assertTrue(e.toString().indexOf("TestKey")>0); 117 assertTrue(e.toString().indexOf("TestValue")>0); 118 119 NoUnitException myException =(NoUnitException)e; 120 assertTrue(myException.getUserErrorMessage().indexOf("TestKey")>0); 121 assertTrue(myException.getUserErrorMessage().indexOf("TestValue")>0); 122 } 123 124 } 125 126 129 public void testException3Values() 130 { 131 132 try { 133 if (true) 135 throw new NoUnitException("TestKey","TestValue","TestReason"); 136 fail("Expected Exception Not thrown"); 137 } 138 catch (Exception e) 139 { 140 assertTrue(e instanceof Exception ); 142 assertTrue(e instanceof NoUnitException); 143 assertTrue(e.toString()!=null); 144 assertTrue(e.toString().indexOf("TestKey")>0); 145 assertTrue(e.toString().indexOf("TestValue")>0); 146 assertTrue(e.toString().indexOf("TestReason")>0); 147 148 NoUnitException myException =(NoUnitException)e; 149 assertTrue(myException.getUserErrorMessage().indexOf("TestKey")>0); 150 assertTrue(myException.getUserErrorMessage().indexOf("TestValue")>0); 151 assertTrue(myException.getUserErrorMessage().indexOf("TestReason")>0); 152 153 } 154 155 } 156 157 } 158 | Popular Tags |