LogManagerProperties extends Properties { static Formatter newFormatter(String name) throws Exception { return newObjectFrom(name, Formatter.class); } LogManagerProperties(final Properties parent, final String prefix); @Override 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 testNewFormatter() throws Exception { try { LogManagerProperties.newFormatter(null); fail("Null was allowed."); } catch (NullPointerException expect) { } try { LogManagerProperties.newFormatter(""); fail("Empty class was allowed."); } catch (ClassNotFoundException expect) { } try { LogManagerProperties.newFormatter(Object.class.getName()); fail("Wrong type was allowed."); } catch (ClassCastException expect) { } final Class<?> type = SimpleFormatter.class; final Formatter f = LogManagerProperties.newFormatter(type.getName()); assertEquals(type, f.getClass()); setPending(new RuntimeException()); try { final String name = ErrorFormatter.class.getName(); LogManagerProperties.newFormatter(name); fail("Exception was not thrown."); } catch (InvocationTargetException expect) { assertEquals(RuntimeException.class, expect.getCause().getClass()); } finally { setPending(null); } }
@Test public void testEscapingFormatter() throws Exception { try { Class<?> k = ErrorFormatter.class; Formatter f; f = LogManagerProperties.newFormatter(k.getName()); assertEquals(k, f.getClass()); setPending(new ThreadDeath()); try { f = LogManagerProperties.newFormatter(k.getName()); fail(String.valueOf(f)); } catch (ThreadDeath expect) { } setPending(new OutOfMemoryError()); try { f = LogManagerProperties.newFormatter(k.getName()); fail(String.valueOf(f)); } catch (OutOfMemoryError expect) { } } finally { setPending(null); } }