### Question:
SimpleLogListener implements LogListener, XmlConfigurable, Consumer<LogEventWriter> { @Override public void setConfiguration(Element e) throws ConfigurationException { Element ew = e.getChild("writer"); LogEventWriter writer; if (ew != null) { String clazz = ew.getAttributeValue("class"); if (clazz != null) { try { writer = (LogEventWriter) Class.forName(clazz).newInstance(); } catch (Exception ex) { throw new ConfigurationException(ex); } if (writer != null) { if (writer instanceof Configurable) { SimpleConfigurationFactory factory = new SimpleConfigurationFactory(); ((Configurable) writer).setConfiguration(factory.getConfiguration(ew)); } if (writer instanceof XmlConfigurable) { ((XmlConfigurable) writer).setConfiguration(ew); } accept(writer); } } else { throw new ConfigurationException("The writer configuration requires a class attribute"); } } } SimpleLogListener();  SimpleLogListener(PrintStream p); synchronized void setPrintStream(PrintStream p); synchronized void close(); synchronized LogEvent log(LogEvent ev); @Override void accept(LogEventWriter writer); @Override void setConfiguration(Element e);  }### Answer:
@Test void testSetConfigurationShouldNotCreateAndSetWriterIfNotPresent() throws ConfigurationException { SimpleLogListener simpleLogListener = new SimpleLogListener(); Element root = new Element("root"); simpleLogListener.setConfiguration(root); assertNull(simpleLogListener.writer); }
@Test void testSetConfigurationShouldThrowConfigurationExceptionOnNewInstanceFailure() { SimpleLogListener simpleLogListener = new SimpleLogListener(); Element root = new Element("root"); Element we = new Element("writer"); Element prop = new Element("property"); we.setAttribute("class", "org.jpos.util.FakeLogEventWriter"); we.addContent(prop); root.addContent(we); assertThrows(ConfigurationException.class, () -> simpleLogListener.setConfiguration(root)); }
@Test void testSetConfigurationShouldThrowConfigurationExceptionWhenWriterClassAttributeMissing() { SimpleLogListener simpleLogListener = new SimpleLogListener(); Element root = new Element("root"); Element we = new Element("writer"); root.addContent(we); assertThrows(ConfigurationException.class, () -> simpleLogListener.setConfiguration(root)); }