### Question:
ChronicleMapRetryFailoverPolicy implements FailoverPolicy<ItemSource>, LifeCycle { boolean tryPut(CharSequence key, ItemSource failedItem) { if (failedItem == null) { return false; } try { failedItems.put(key, failedItem); return true; } catch (Exception e) { storeFailureCount.incrementAndGet(); LOGGER.error("Unable to store {}. Cause: {}", failedItem.getClass().getSimpleName(), e.getMessage()); return false; } } protected  ChronicleMapRetryFailoverPolicy(Builder builder); @Override void addListener(U failoverListener); @Override void deliver(ItemSource failedItemSource); @PluginBuilderFactory static ChronicleMapRetryFailoverPolicy.Builder newBuilder(); @Override void start(); @Override void stop(); @Override LifeCycle stop(long timeout, boolean async); @Override boolean isStarted(); @Override boolean isStopped(); static final String PLUGIN_NAME; }### Answer:
@Test public void failedItemIsStoredIfBothKeyAndFailedItemAreNotNull() throws IOException { String fileName = createTempFile().getAbsolutePath(); ChronicleMap<CharSequence, ItemSource> failedItems = createDefaultTestChronicleMap(); ChronicleMapRetryFailoverPolicy.Builder builder = createDefaultTestFailoverPolicyBuilder(fileName, failedItems); ChronicleMapRetryFailoverPolicy failoverPolicy = builder.build(); ItemSource<Object> failedItemSource = mock(FailedItemSource.class); String expectedKey = UUID.randomUUID().toString(); boolean result = failoverPolicy.tryPut(expectedKey, failedItemSource); assertTrue(result); verify(failedItems).put(eq(expectedKey), eq(failedItemSource)); }
@Test public void failedItemIsNotStoredIfFailedItemIsNull() throws IOException { String fileName = createTempFile().getAbsolutePath(); ChronicleMap<CharSequence, ItemSource> failedItems = createDefaultTestChronicleMap(); ChronicleMapRetryFailoverPolicy.Builder builder = createDefaultTestFailoverPolicyBuilder(fileName, failedItems); ChronicleMapRetryFailoverPolicy failoverPolicy = builder.build(); CharSequence unexpectedKey = UUID.randomUUID().toString(); boolean result = failoverPolicy.tryPut(unexpectedKey, null); assertFalse(result); verify(failedItems, times(0)).put(eq(unexpectedKey), any()); }
@Test public void exceptionCountIsIncrementedOnStorageFailure() throws IOException { ChronicleMapRetryFailoverPolicy failoverPolicy = createDefaultTestFailoverPolicyBuilder().build(); ItemSource<Object> failedItemSource = mock(FailedItemSource.class); boolean result = failoverPolicy.tryPut(null, failedItemSource); assertFalse(result); assertEquals(1, failoverPolicy.storeFailureCount.get()); }