### Question:
DefaultDeliveryClient implements DeliveryClient { @Override public void enqueueEventForDelivery(final InternalEvent event) { final long startEnqueueTimeMillis = System.currentTimeMillis(); final long origEventsProcessed = eventsProcessed.get(); eventsRunnableQueue.execute(new Runnable() { @Override public void run() { long start = System.currentTimeMillis(); try { boolean eventStored = eventStore.put(eventAdapter.translateFromEvent(event) .toString()); if (eventStored) { Log.i(TAG, String.format("Event: '%s' recorded to local filestore", StringUtil.clipString(event.getEventType(), CLIPPED_EVENT_LENGTH, true))); Log.d(TAG, String.format("Time of enqueueEventForDelivery: %d", System.currentTimeMillis() - start)); } else { Log.w(TAG, String.format( "Event: '%s' failed to record to local filestore", StringUtil.clipString(event.getEventType(), CLIPPED_EVENT_LENGTH, true))); } } catch (EventStoreException e) { Log.w(TAG, String.format("Event: '%s' failed to record to local filestore", StringUtil.clipString(event.getEventType(), CLIPPED_EVENT_LENGTH, true))); } finally { calculateAndSetAverageWriteEventTime(origEventsProcessed, startEnqueueTimeMillis); } } }); } DefaultDeliveryClient(AnalyticsContext context, DefaultDeliveryPolicyFactory policyFactory,
            final ExecutorService eventsRunnableQueue,
            final ExecutorService submissionRunnableQueue, ERSRequestBuilder requestBuilder,
            EventStore eventStore,
            EventAdapter<JSONObject> eventAdapter); static DefaultDeliveryClient newInstance(AnalyticsContext context,
            boolean allowWANDelivery); @Override void notify(InternalEvent event); @Override void enqueueEventForDelivery(final InternalEvent event); @Override void attemptDelivery(); void attemptDelivery(final List<DeliveryPolicy> policies); static final String EVENTS_DIRECTORY; }### Answer:
@Test public void enqueueEventForDelivery_writeMultipleEventsToDisk_eventsStoredInNewlineFile() throws JSONException { InternalEvent mockEvent = mock(InternalEvent.class); when(mockEvent.getEventType()).thenReturn("event_type"); JSONObject expectedJson = new JSONObject(); expectedJson.put("event_type", "event_type"); when(mockAdapter.translateFromEvent(mockEvent)).thenReturn(expectedJson); target.enqueueEventForDelivery(mockEvent); target.enqueueEventForDelivery(mockEvent); target.enqueueEventForDelivery(mockEvent); ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class); verify(mockEventExecutor, times(3)).execute(runnableCaptor.capture()); assertThat(runnableCaptor.getAllValues().size(), is(3)); for (Runnable runnable : runnableCaptor.getAllValues()) { runnable.run(); } ArgumentCaptor<String> putEventCaptor = ArgumentCaptor.forClass(String.class); verify(mockEventStore, times(3)).put(putEventCaptor.capture()); assertThat(putEventCaptor.getAllValues().size(), is(3)); for (String eventString : putEventCaptor.getAllValues()) { assertThat(eventString, is(expectedJson.toString())); } }