### Question:
MappingLogEventWriter extends BaseLogEventWriter implements XmlConfigurable { protected LogEvent mapEvents(LogEvent ev) { if (eventMappers != null) { for (LogEventMapper mapper : eventMappers) { ev = mapper.apply(ev); } } return ev; }  @Override void setPrintStream(PrintStream p); @Override synchronized void close(); @Override void write(LogEvent ev); @Override void setConfiguration(Element e);  }### Answer:
@Test void testMapEventsShouldCallEventMappersInOrderAndReturnFinalResult() { MappingLogEventWriter writer = new MappingLogEventWriter(); List<LogEventMapper> mappers = new ArrayList<>(); writer.eventMappers = mappers; mappers.add(logEvent -> { logEvent.addMessage("1"); return logEvent; }); mappers.add(logEvent -> { logEvent.addMessage("2"); return logEvent; }); LogEvent ev = new LogEvent(); LogEvent logEvent = writer.mapEvents(ev); assertEquals(2, logEvent.getPayLoad().size()); assertEquals("1", logEvent.getPayLoad().get(0)); assertEquals("2", logEvent.getPayLoad().get(1)); }
@Test void testMapEventsShouldNotThrowExceptionWhenEventMappersIsNull() { MappingLogEventWriter writer = new MappingLogEventWriter(); assertDoesNotThrow(() -> writer.mapEvents(new LogEvent())); }