### Question:
ElasticsearchAppender extends AbstractAppender { public void append(LogEvent event) { String formattedIndexName = indexNameFormatter.format(event); itemAppender.append(formattedIndexName, event); } protected  ElasticsearchAppender(String name, Filter filter, Layout layout,
            boolean ignoreExceptions, BatchDelivery batchDelivery, boolean messageOnly, IndexNameFormatter indexNameFormatter); void append(LogEvent event); @PluginBuilderFactory static Builder newBuilder(); @Override void start(); @Override void stop(); @Override boolean stop(long timeout, TimeUnit timeUnit); static final String PLUGIN_NAME; }### Answer:
@Test public void appenderDelegatesToItemAppender() { ItemAppender itemAppender = mock(ItemAppender.class); ItemAppenderFactory itemAppenderFactory = mockedItemAppenderFactory(); when(itemAppenderFactory.createInstance(anyBoolean(), any(AbstractLayout.class), any(BatchDelivery.class))) .thenReturn(itemAppender); ElasticsearchAppender appender = createTestElasticsearchAppender(itemAppenderFactory); LogEvent logEvent = mock(LogEvent.class); when(logEvent.getTimeMillis()).thenReturn(System.currentTimeMillis()); appender.append(logEvent); verify(itemAppender, times(1)).append(anyString(), eq(logEvent)); }
@Test public void appenderUsesProvidedLayoutWhenMessageOnlyIsSetToFalse() { Layout layout = PowerMockito.mock(Layout.class); ElasticsearchAppender.Builder builder = ElasticsearchAppenderTest.createTestElasticsearchAppenderBuilder(); builder.withMessageOnly(false); builder.withLayout(layout); LogEvent logEvent = mock(LogEvent.class); ElasticsearchAppender appender = builder.build(); appender.append(logEvent); ArgumentCaptor<LogEvent> captor = ArgumentCaptor.forClass(LogEvent.class); verify(layout, times(1)).toSerializable(captor.capture()); assertEquals(logEvent, captor.getValue()); }
@Test public void appenderUsesProvidedIndexNameFormatter() { BatchDelivery<String> batchDelivery = mock(BatchDelivery.class); IndexNameFormatter indexNameFormatter = mock(IndexNameFormatter.class); when(indexNameFormatter.format(any(LogEvent.class))).thenReturn("formattedIndexName"); ElasticsearchAppender.Builder builder = ElasticsearchAppenderTest.createTestElasticsearchAppenderBuilder(); builder.withBatchDelivery(batchDelivery); builder.withMessageOnly(false); builder.withIndexNameFormatter(indexNameFormatter); LogEvent logEvent = createTestLogEvent(); ElasticsearchAppender appender = builder.build(); appender.append(logEvent); verify(batchDelivery, times(1)).add(eq("formattedIndexName"), any(ItemSource.class)); }