### Question:
ProtectedLogListener implements LogListener, Configurable { public void setConfiguration (Configuration cfg) throws ConfigurationException { this.cfg = cfg; protectFields = ISOUtil.toStringArray (cfg.get ("protect", "")); wipeFields = ISOUtil.toStringArray (cfg.get ("wipe", "")); } ProtectedLogListener(); void setConfiguration(Configuration cfg); LogEvent log(LogEvent ev); static final String WIPED; static final byte[] BINARY_WIPED; }### Answer:
@Test public void testSetConfiguration() throws Throwable { ProtectedLogListener protectedLogListener = new ProtectedLogListener(); Configuration cfg = new SimpleConfiguration(); protectedLogListener.setConfiguration(cfg); assertEquals(0, protectedLogListener.protectFields.length, "protectedLogListener.protectFields.length"); assertEquals(0, protectedLogListener.wipeFields.length, "protectedLogListener.wipeFields.length"); assertSame(cfg, protectedLogListener.cfg, "protectedLogListener.cfg"); }
@Test public void testSetConfigurationThrowsNullPointerException() throws Throwable { ProtectedLogListener protectedLogListener = new ProtectedLogListener(); Configuration cfg = new SubConfiguration(); try { protectedLogListener.setConfiguration(cfg); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertSame(cfg, protectedLogListener.cfg, "protectedLogListener.cfg"); if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.core.Configuration.get(String, String)\" because \"this.cfg\" is null", ex.getMessage(), "ex.getMessage()"); } assertNull(protectedLogListener.wipeFields, "protectedLogListener.wipeFields"); assertNull(protectedLogListener.protectFields, "protectedLogListener.protectFields"); } }