1 package net.sf.openrocket.logging;
3 import static org.junit.Assert.*;
7 public class TraceExceptionTest {
9 private TraceException getViaAccess() {
12 * The SubClass test bases on the fact that getViaAccess method is defined on a row number < 20
13 * and the return statement is on a row number > 20.
15 * The JRE sometimes adds an additional "access$NNN" method call between the calls with the
16 * row number equal to the method definition line.
26 return new TraceException(0, 1);
31 public void testBasic() {
32 TraceException trace = new TraceException();
33 assertMatch("\\(TraceExceptionTest.java:[2-9][0-9]\\)", trace);
38 public void testOneLevelUp() {
39 // @formatter:off - these need to be on the same line number
40 TraceException trace = getOneLevelUp(); TraceException ref = new TraceException();
42 assertEquals(ref.getMessage(), trace.getMessage());
45 private TraceException getOneLevelUp() {
46 return new TraceException(1);
51 public void testTwoLevels() {
52 TraceException trace = getTwoLevels();
53 assertMatch("\\(TraceExceptionTest.java:[2-9][0-9] TraceExceptionTest.java:[2-9][0-9]\\)", trace);
56 private TraceException getTwoLevels() {
57 return new TraceException(0, 1);
62 public void testViaSubclass() {
64 * This tests that TraceException.getMessage ignores the synthetic "access$0" method calls.
67 TraceException trace = new SubClass().getTrace();
68 assertMatch("\\(TraceExceptionTest.java:[2-9][0-9] TraceExceptionTest.java:[2-9][0-9]\\)", trace);
71 private class SubClass {
72 private TraceException getTrace() {
73 return getViaAccess();
81 private void assertMatch(String regex, TraceException trace) {
82 boolean match = trace.getMessage().matches(regex);
84 trace.printStackTrace();
85 assertTrue("Was: " + trace.getMessage(), match);