1 8 package test.afterxxx; 9 10 import junit.framework.TestCase; 11 12 public class Test extends TestCase { 13 private static String s_log; 14 15 public static void log(String msg) { 16 s_log += msg; 17 } 18 19 public void testAll() { 20 s_log = ""; 21 all(); 22 assertEquals("logAround ", s_log); 23 } 24 25 public void testAroundFinally() { 26 s_log = ""; 27 aroundFinally(); 28 assertEquals("logAround logAfterFinally ", s_log); 29 } 30 31 public void testAroundFinallyReturning() { 32 s_log = ""; 33 aroundFinallyReturning(); 34 assertEquals("logAround logAfterReturning logAfterFinally ", s_log); 35 } 36 37 public void testAroundReturning() { 38 s_log = ""; 39 aroundReturning(); 40 assertEquals("logAround logAfterReturningString logAfterReturning ", s_log); 41 } 42 43 public void testAroundFinallyReturningThrowing() { 44 s_log = ""; 45 try { 46 aroundFinallyReturningThrowing(); 47 } catch (UnsupportedOperationException e) { 48 } 49 assertEquals("logAround logAfterThrowingRTE logAfterFinally ", s_log); 50 } 51 52 public void testAroundReturningThrowing() { 53 s_log = ""; 54 try { 55 aroundReturningThrowing(); 56 } catch (UnsupportedOperationException e) { 57 } 58 assertEquals("logAround logAfterThrowingRTE ", s_log); 59 } 60 61 public void testFinally() { 62 s_log = ""; 63 _finally(); 64 assertEquals("logAfterFinally ", s_log); 65 } 66 67 public void testFinallyReturning() { 68 s_log = ""; 69 finallyReturning(); 70 assertEquals("logAfterReturningString logAfterReturning logAfter logAfterFinally ", s_log); 71 } 72 73 public void testFinallyReturningThrowing() { 74 s_log = ""; 75 try { 76 finallyReturningThrowing(); 77 } catch (UnsupportedOperationException e) { 78 } 79 assertEquals("logAfterThrowingRTE logAfterFinally ", s_log); 80 } 81 82 public void testReturning() { 83 s_log = ""; 84 returning(); 85 assertEquals("logAfterReturningString logAfterReturning ", s_log); 86 } 87 88 public void testReturningThrowing() { 89 s_log = ""; 90 try { 91 returningThrowing(); 92 } catch (Exception e) { 93 } 94 assertEquals("", s_log); 95 } 96 97 public Test(String name) { 98 super(name); 99 } 100 101 public static void main(String [] args) { 102 junit.textui.TestRunner.run(suite()); 103 } 104 105 public static junit.framework.Test suite() { 106 return new junit.framework.TestSuite(Test.class); 107 } 108 109 void all() { 110 } 111 112 void aroundFinally() { 113 } 114 115 static Object aroundFinallyReturning() { 116 return null; 117 } 118 119 Object aroundReturning() { 120 return "aroundReturning"; 121 } 122 123 static Object aroundFinallyReturningThrowing() { 124 throw new UnsupportedOperationException (); 125 } 126 127 Object aroundReturningThrowing() { 128 throw new UnsupportedOperationException (); 129 } 130 131 void _finally() { 132 } 133 134 static Object finallyReturning() { 135 return "finallyReturning"; 136 } 137 138 static Object finallyReturningThrowing() { 139 throw new UnsupportedOperationException (); 140 } 141 142 Object returningThrowing() throws Exception { 143 throw new Exception (); 144 } 145 146 Object returning() { 147 return "returning"; 148 } 149 } | Popular Tags |