SeverityComparator implements Comparator<LogRecord>, Serializable { public int compareThrowable(final Throwable t1, final Throwable t2) { if (t1 == t2) { return 0; } else { if (t1 == null) { return isNormal(t2) ? 1 : -1; } else { if (t2 == null) { return isNormal(t1) ? -1 : 1; } } if (t1.getClass() == t2.getClass()) { return 0; } if (isNormal(t1)) { return isNormal(t2) ? 0 : -1; } else { if (isNormal(t2)) { return 1; } } if (t1 instanceof Error) { return t2 instanceof Error ? 0 : 1; } else if (t1 instanceof RuntimeException) { return t2 instanceof Error ? -1 : t2 instanceof RuntimeException ? 0 : 1; } else { return t2 instanceof Error || t2 instanceof RuntimeException ? -1 : 0; } } }  Throwable apply(final Throwable chain); final int applyThenCompare(Throwable tc1, Throwable tc2); int compareThrowable(final Throwable t1, final Throwable t2); int compare(final LogRecord o1, final LogRecord o2); @Override boolean equals(final Object o); @Override int hashCode(); boolean isNormal(final Throwable t);  }
@Test public void testCompareThrownDoesNotApply() { SeverityComparator a = new SeverityComparator(); Throwable tc1 = new Error(new Exception()); Throwable tc2 = new Exception(new Exception()); assertTrue(a.compareThrowable(tc1, tc2) > 0); assertTrue(a.compareThrowable(tc2, tc1) < 0); tc1 = new RuntimeException(tc1); assertTrue(a.compareThrowable(tc1, tc2) > 0); assertTrue(a.compareThrowable(tc2, tc1) < 0); }
@Test public void testCompareThrownNull() { SeverityComparator a = new SeverityComparator(); assertEquals(0, a.compareThrowable((Throwable) null, (Throwable) null)); assertTrue(a.compareThrowable(new Throwable(), (Throwable) null) > 0); assertTrue(a.compareThrowable((Throwable) null, new Throwable()) < 0); }