CollectorFormatter extends Formatter { protected LogRecord apply(final LogRecord t, final LogRecord u) { if (t == null || u == null) { throw new NullPointerException(); } if (comparator != null) { return comparator.compare(t, u) >= 0 ? t : u; } else { return u; } } CollectorFormatter();  CollectorFormatter(String format);  CollectorFormatter(String format, Formatter f,
            Comparator<? super LogRecord> c); @Override String format(final LogRecord record); @Override String getTail(final Handler h); @Override String toString();  }
@Test(expected = NullPointerException.class) public void testApplyNullAndNull() { CollectorFormatter f = new CollectorFormatter("{3}", (Formatter) null, (Comparator<LogRecord>) null); f.apply((LogRecord) null, (LogRecord) null); }
@Test(expected = NullPointerException.class) public void testApplyNullAndLogRecord() { CollectorFormatter f = new CollectorFormatter("{3}", (Formatter) null, (Comparator<LogRecord>) null); f.apply((LogRecord) null, new LogRecord(Level.SEVERE, "")); }
@Test(expected = NullPointerException.class) public void testApplyLogRecordAndNull() { CollectorFormatter f = new CollectorFormatter("{3}", (Formatter) null, (Comparator<LogRecord>) null); f.apply(new LogRecord(Level.SEVERE, ""), (LogRecord) null); }
@Test public void testApplyWithoutComparator() { CollectorFormatter f = new CollectorFormatter("{3}", (Formatter) null, (Comparator<LogRecord>) null); LogRecord first = new LogRecord(Level.SEVERE, ""); LogRecord second = new LogRecord(Level.WARNING, ""); assertSame(second, f.apply(first, second)); }
@Test public void testApplyWithComparator() { CollectorFormatter f = new CollectorFormatter("{3}", (Formatter) null, SeverityComparator.getInstance()); LogRecord first = new LogRecord(Level.SEVERE, ""); LogRecord second = new LogRecord(Level.WARNING, ""); assertSame(first, f.apply(first, second)); }