1 19 20 package org.netbeans.api.debugger.jpda; 21 22 import org.netbeans.api.debugger.DebuggerManager; 23 import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent; 24 import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener; 25 import org.netbeans.junit.NbTestCase; 26 27 32 public class ExceptionBreakpointTest extends NbTestCase { 33 34 private JPDASupport support; 35 private DebuggerManager dm = DebuggerManager.getDebuggerManager (); 36 37 private static final String CLASS_NAME = 38 "org.netbeans.api.debugger.jpda.testapps.ExceptionBreakpointApp"; 39 40 41 public ExceptionBreakpointTest (String s) { 42 super (s); 43 } 44 45 public void testMethodBreakpoints () throws Exception { 46 try { 47 ExceptionBreakpoint eb1 = ExceptionBreakpoint.create ( 48 "org.netbeans.api.debugger.jpda.testapps.ExceptionTestException", 49 ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED 50 ); 51 TestBreakpointListener tbl = new TestBreakpointListener ( 52 "org.netbeans.api.debugger.jpda.testapps.ExceptionTestException", 53 eb1, 54 1 55 ); 56 eb1.addJPDABreakpointListener (tbl); 57 dm.addBreakpoint (eb1); 58 59 support = JPDASupport.attach (CLASS_NAME); 60 61 for (;;) { 62 support.waitState (JPDADebugger.STATE_STOPPED); 63 if (support.getDebugger ().getState () == 64 JPDADebugger.STATE_DISCONNECTED 65 ) break; 66 support.doContinue (); 67 } 68 tbl.assertFailure (); 69 70 dm.removeBreakpoint (eb1); 71 } finally { 72 support.doFinish (); 73 } 74 } 75 76 private class TestBreakpointListener implements JPDABreakpointListener { 77 78 private int hitCount; 79 private AssertionError failure; 80 private String exceptionClass; 81 private ExceptionBreakpoint bpt; 82 private int expectedHitCount; 83 84 public TestBreakpointListener ( 85 String exceptionClass, 86 ExceptionBreakpoint bpt, 87 int expectedHitCount 88 ) { 89 this.exceptionClass = exceptionClass; 90 this.bpt = bpt; 91 this.expectedHitCount = expectedHitCount; 92 } 93 94 public void breakpointReached (JPDABreakpointEvent event) { 95 try { 96 checkEvent (event); 97 } catch (AssertionError e) { 98 failure = e; 99 } catch (Throwable e) { 100 failure = new AssertionError (e); 101 } 102 } 103 104 private void checkEvent (JPDABreakpointEvent event) { 105 assertEquals ( 106 "Breakpoint event: Bad exception location", 107 CLASS_NAME, 108 event.getReferenceType ().name () 109 ); 110 assertEquals ( 111 "Breakpoint event: Bad exception thrown", 112 exceptionClass, 113 event.getVariable ().getType () 114 ); 115 assertSame ( 116 "Breakpoint event: Bad event source", 117 bpt, 118 event.getSource () 119 ); 120 assertEquals ( 121 "Breakpoint event: Condition evaluation failed", 122 JPDABreakpointEvent.CONDITION_NONE, 123 event.getConditionResult () 124 ); 125 assertNotNull ( 126 "Breakpoint event: Context thread is null", 127 event.getThread () 128 ); 129 hitCount++; 130 } 131 132 public void assertFailure () { 133 if (failure != null) throw failure; 134 assertEquals ( 135 "Breakpoint hit count mismatch", 136 expectedHitCount, 137 hitCount 138 ); 139 } 140 } 141 } 142 | Popular Tags |