1 7 package ch.ethz.prose.crosscut; 8 9 import java.io.IOException ; 11 12 import junit.framework.*; 13 import ch.ethz.prose.DefaultAspect; 14 import ch.ethz.prose.ProseSystem; 15 import ch.ethz.prose.filter.PointCutter; 16 17 23 public 24 class ExceptionCutUserDefinedTest extends TestCase { 25 26 public static class MyRuntimeException extends RuntimeException {}; 28 public static class MyException extends IOException {}; 29 public static class MyError extends Error {}; 30 31 public static class MySubRuntimeException extends MyRuntimeException {}; 34 public static class MySubException extends MyException {}; 35 public static class MySubError extends MyError {}; 36 public static class MyNullPointerException extends NullPointerException {}; 37 38 public static class TestExtension extends DefaultAspect 39 { 40 int c1cnt=0; 41 int c2cnt=0; 42 int c3cnt=0; 43 int c4cnt=0; 44 45 public Crosscut c1 = new ThrowCut() 46 { 47 public void THROW_ARGS(ANY x) 48 { 49 c1cnt++; 50 } 51 52 protected PointCutter pointCutter() 53 { 54 return null; 55 } 56 }; 57 58 public Crosscut c2 = new ThrowCut() 59 { 60 public void THROW_ARGS(RuntimeException e) 61 { c2cnt++;} 62 63 protected PointCutter pointCutter() 64 { 65 return null; 66 } 67 68 }; 69 70 public Crosscut c3 = new ThrowCut() 71 { 72 public void THROW_ARGS(IOException e) 73 { c3cnt++;} 74 75 protected PointCutter pointCutter() 76 { 77 return null; 78 } 79 80 }; 81 82 public Crosscut c4 = new ThrowCut() 83 { 84 public void THROW_ARGS(Throwable e) 85 {c4cnt++;} 86 87 protected PointCutter pointCutter() 88 { 89 return null; 90 } 91 92 }; 93 } 94 95 99 public ExceptionCutUserDefinedTest(String name) 100 { 101 super(name); 102 } 103 104 107 protected 108 void setUp() throws Exception 109 { 110 ProseSystem.startup(); 111 } 112 113 protected void tearDown() throws Exception 114 { 115 ProseSystem.teardown(); 116 } 117 118 public void testCustomExtensionCut() throws Exception 119 { 120 Class c = MyRuntimeException.class; 122 c=MyException.class; 123 c=MyError.class; 124 c = MySubRuntimeException.class; 125 c = MySubException.class; 126 c = MySubError.class; 127 c = MyNullPointerException.class; 128 TestExtension x = new TestExtension(); 129 ProseSystem.getAspectManager().insert(x); 130 131 try { throw new MySubRuntimeException();} catch (MySubRuntimeException e){} try { throw new MyRuntimeException();} catch (MyRuntimeException e){} try { throw new MyNullPointerException();} catch (MyNullPointerException e){} try { throw new MyException();} catch (MyException e){} try { throw new MySubException();} catch (MySubException e){} try { throw new MyError();} catch (MyError e){} try { throw new MySubError();} catch (MySubError e){} 139 ProseSystem.getAspectManager().withdraw(x); 140 141 assertEquals("exception captured by ANY:",7,x.c1cnt); 142 assertEquals("exception captured by Runtime:",3,x.c2cnt); 143 assertEquals("exception captured by IO:",2,x.c3cnt); 144 assertEquals("exception captured by Throwable:",7,x.c4cnt); 145 } 146 147 151 public static 152 Test suite() 153 { 154 return new TestSuite(ExceptionCutUserDefinedTest.class); 155 } 156 } 157 158 159 160 | Popular Tags |