@Override
    public void handle(FailureBatch failureBatch) {
        failureBatch.getFailures().forEach(failure ->
                indexFailureService.saveWithoutValidation(new IndexFailureImpl(ImmutableMap.<String, Object>builder()
                        .put("letter_id", failure.failedMessage().getId())
                        .put("index", failure.targetIndex())
                        .put("type", failure.failureType().toString())
                        .put("message", failure.failureDetails())
                        .put("timestamp", failure.failedMessage().getTimestamp())
                        .build())));
    }
@Test
    public void handle_allFailuresHandedOverToIndexFailureService() {
        // given
        final DateTime ts = DateTime.now(DateTimeZone.UTC);

        final Indexable indexable1 = mock(Indexable.class);
        when(indexable1.getId()).thenReturn("msg-1");
        when(indexable1.getTimestamp()).thenReturn(ts);

        final Indexable indexable2 = mock(Indexable.class);
        when(indexable2.getId()).thenReturn("msg-2");
        when(indexable2.getTimestamp()).thenReturn(ts);

        final IndexingFailure indexingFailure1 = new IndexingFailure(
                IndexingFailureCause.MappingError, "indexingFailureMessage1",
                "indexingFailureDetails1", Tools.nowUTC(), indexable1, "index1");

        final IndexingFailure indexingFailure2 = new IndexingFailure(
                IndexingFailureCause.MappingError, "indexingFailureMessage2",
                "indexingFailureDetails2", Tools.nowUTC(), indexable2, "index2");

        final FailureBatch indexingFailureBatch = FailureBatch.indexingFailureBatch(ImmutableList.of(indexingFailure1, indexingFailure2));

        // when
        underTest.handle(indexingFailureBatch);

        // then
        verify(indexFailureService, times(2)).saveWithoutValidation(any());

        verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg ->
                arg.asMap().get("letter_id").equals("msg-1") &&
                        arg.asMap().get("index").equals("index1") &&
                        arg.asMap().get("type").equals("indexing") &&
                        arg.asMap().get("message").equals("indexingFailureDetails1") &&
                        arg.asMap().get("timestamp") != null
                ));

        verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg ->
                arg.asMap().get("letter_id").equals("msg-2") &&
                        arg.asMap().get("index").equals("index2") &&
                        arg.asMap().get("type").equals("indexing") &&
                        arg.asMap().get("message").equals("indexingFailureDetails2") &&
                        arg.asMap().get("timestamp") != null
        ));
    }