LogManagerProperties extends Properties { static Authenticator newAuthenticator(String name) throws Exception { return newObjectFrom(name, Authenticator.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 testNewAuthenticator() throws Exception { try { LogManagerProperties.newAuthenticator(null); fail("Null was allowed."); } catch (NullPointerException expect) { } try { LogManagerProperties.newAuthenticator(""); fail("Empty class was allowed."); } catch (ClassNotFoundException expect) { } try { LogManagerProperties.newAuthenticator(Object.class.getName()); fail("Wrong type was allowed."); } catch (ClassCastException expect) { } final Class<?> type = ErrorAuthenticator.class; final javax.mail.Authenticator a = LogManagerProperties.newAuthenticator(type.getName()); assertEquals(type, a.getClass()); setPending(new RuntimeException()); try { LogManagerProperties.newAuthenticator(type.getName()); fail("Exception was not thrown."); } catch (InvocationTargetException expect) { assertEquals(RuntimeException.class, expect.getCause().getClass()); } finally { setPending(null); } }
@Test public void testEscapingAuthenticator() throws Exception { try { Class<?> k = ErrorAuthenticator.class; javax.mail.Authenticator a; a = LogManagerProperties.newAuthenticator(k.getName()); assertEquals(k, a.getClass()); setPending(new ThreadDeath()); try { a = LogManagerProperties.newAuthenticator(k.getName()); fail(String.valueOf(a)); } catch (ThreadDeath expect) { } setPending(new OutOfMemoryError()); try { a = LogManagerProperties.newAuthenticator(k.getName()); fail(String.valueOf(a)); } catch (OutOfMemoryError expect) { } } finally { setPending(null); } }