### Question:
StringItemSourceFactory implements ItemSourceFactory { @Override public ItemSource create(Object event, ObjectWriter objectWriter) { try { return new StringItemSource(objectWriter.writeValueAsString(event)); } catch (JsonProcessingException e) { LOGGER.error("Cannot write item source: " + e.getMessage()); return null; } } StringItemSourceFactory(); @Override final boolean isBuffered(); @Override ItemSource create(Object event, ObjectWriter objectWriter); @Override ItemSource createEmptySource(); @PluginBuilderFactory static Builder newBuilder(); @Override void start(); @Override void stop(); @Override boolean isStarted(); @Override boolean isStopped();  }### Answer:
@Test public void createWritesItemSource() throws IOException { StringItemSourceFactory factory = createDefaultTestStringItemSourceFactory(); LogEvent logEvent = mock(LogEvent.class); ObjectWriter objectWriter = spy(new ObjectMapper().writerFor(LogEvent.class)); ItemSource itemSource = factory.create(logEvent, objectWriter); assertNotNull(itemSource); verify(objectWriter).writeValueAsString(eq(logEvent)); }
@Test public void createFailureIsHandled() throws IOException { StringItemSourceFactory factory = createDefaultTestStringItemSourceFactory(); LogEvent logEvent = mock(LogEvent.class); ObjectWriter objectWriter = spy(new ObjectMapper().writerFor(LogEvent.class)); doThrow(JsonMappingException.fromUnexpectedIOE(new IOException("test exception"))).when(objectWriter).writeValueAsString(eq(logEvent)); ItemSource itemSource = factory.create(logEvent, objectWriter); assertNull(itemSource); }