StacktraceHash implements IStacktraceHash { @Override public String hash(final IStacktrace st) throws StacktraceHashException { return hashString(st.getStacktraceText()); } StacktraceHash(final String algorithm);  StacktraceHash(); String getAlgorithm(); @Override String hash(final IStacktrace st); boolean isAlgorithmAvailable(); static final String DEFAULT_ALGORITHM; }
@Test public void testHashLineNumberFalse() throws Throwable { StacktraceHash h = new StacktraceHash(StacktraceHash.DEFAULT_ALGORITHM); Throwable t1 = null; Throwable t2 = null; try { new TestClass().foo(1); } catch (RuntimeException e) { t1 = e; } try { new TestClass().foo(2); } catch (RuntimeException e) { t2 = e; } assertEquals( h.hash(Stacktrace.getInstance(t1, false)), h.hash(Stacktrace.getInstance(t2, false)) ); }
@Test public void testHashLineNumberTrue() throws Throwable { StacktraceHash h = new StacktraceHash(StacktraceHash.DEFAULT_ALGORITHM); Throwable t1 = null; Throwable t2 = null; try { new TestClass().foo(1); } catch (RuntimeException e) { t1 = e; } try { new TestClass().foo(2); } catch (RuntimeException e) { t2 = e; } assertNotEquals( h.hash(Stacktrace.getInstance(t1, true)), h.hash(Stacktrace.getInstance(t2, true)) ); }
@Test public void testHashCause() throws Throwable { StacktraceHash h = new StacktraceHash(); Throwable t1 = null; Throwable t2 = null; try { new TestClass().foo(1); } catch (RuntimeException e) { t1 = e; } try { new TestClass().foo(1); } catch (RuntimeException e) { t2 = e; } assertEquals( h.hash(Stacktrace.getInstance(t1)), h.hash(Stacktrace.getInstance(t2)) ); if (t1 != null) { t1.initCause(new RuntimeException("cause")); } assertNotEquals( h.hash(Stacktrace.getInstance(t1)), h.hash(Stacktrace.getInstance(t2)) ); }