LogManagerProperties extends Properties { @SuppressWarnings("unchecked") static Comparator<? super LogRecord> newComparator(String name) throws Exception { return newObjectFrom(name, Comparator.class); } LogManagerProperties(final Properties parent, final String prefix); @Override @SuppressWarnings("CloneDoesntCallSuperClone") synchronized Object clone(); @Override synchronized String getProperty(final String key); @Override String getProperty(final String key, final String def); @Override Object get(final Object key); @Override synchronized Object put(final Object key, final Object value); @Override Object setProperty(String key, String value); @Override boolean containsKey(final Object key); @Override synchronized Object remove(final Object key); @Override Enumeration<?> propertyNames(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testNewComparator() throws Exception { try { LogManagerProperties.newComparator(null); fail("Null was allowed."); } catch (NullPointerException expect) { } try { LogManagerProperties.newComparator(""); fail("Empty class was allowed."); } catch (ClassNotFoundException expect) { } try { LogManagerProperties.newComparator(Object.class.getName()); fail("Wrong type was allowed."); } catch (ClassCastException expect) { } final Class<?> type = ErrorComparator.class; final Comparator<? super LogRecord> c = LogManagerProperties.newComparator(type.getName()); assertEquals(type, c.getClass()); setPending(new RuntimeException()); try { LogManagerProperties.newComparator(type.getName()); fail("Exception was not thrown."); } catch (InvocationTargetException expect) { assertEquals(RuntimeException.class, expect.getCause().getClass()); } finally { setPending(null); } }
@Test public void testEscapingComparator() throws Exception { try { Class<?> k = ErrorComparator.class; Comparator<? super LogRecord> c; c = LogManagerProperties.newComparator(k.getName()); assertEquals(k, c.getClass()); setPending(new ThreadDeath()); try { c = LogManagerProperties.newComparator(k.getName()); fail(String.valueOf(c)); } catch (ThreadDeath expect) { } setPending(new OutOfMemoryError()); try { c = LogManagerProperties.newComparator(k.getName()); fail(String.valueOf(c)); } catch (OutOfMemoryError expect) { } } finally { setPending(null); } }