### Question:
SyncFailureHandlerFactoryImpl implements SyncFailureHandlerFactory { public SyncFailureHandler create(JsonValue config) { if (null == config || config.isNull()) { return InfiniteRetrySyncFailureHandler.INSTANCE; } JsonValue maxRetries = config.get(CONFIG_MAX_RETRIES); JsonValue postRetry = config.get(CONFING_POST_RETRY); if (maxRetries.isNull() || maxRetries.asInteger() < 0) { return InfiniteRetrySyncFailureHandler.INSTANCE; } else if (maxRetries.asInteger() == 0) { return getPostRetryHandler(postRetry); } else { return new SimpleRetrySyncFailureHandler(maxRetries.asInteger(), getPostRetryHandler(postRetry)); } }  SyncFailureHandler create(JsonValue config); static final String PID; }### Answer:
@Test public void testCreateNoConfig() throws Exception { SyncFailureHandler handler = factory.create(null); Assert.assertTrue(handler instanceof InfiniteRetrySyncFailureHandler); }
@Test public void testCreateNullConfig() throws Exception { SyncFailureHandler handler = factory.create(new JsonValue(null)); Assert.assertTrue(handler instanceof InfiniteRetrySyncFailureHandler); }
@Test public void testCreateEmptyConfig() throws Exception { SyncFailureHandler handler = factory.create(new JsonValue(new HashMap<String,Object>())); Assert.assertTrue(handler instanceof InfiniteRetrySyncFailureHandler); }
@Test public void testCreateInfiniteRetry() throws Exception { JsonValue config = parseJsonString("{\"maxRetries\":-1}"); SyncFailureHandler handler = factory.create(config); Assert.assertTrue(handler instanceof InfiniteRetrySyncFailureHandler); }
@Test public void testCreateLoggedIgnore() throws Exception { JsonValue config = parseJsonString("{\"maxRetries\":0,\"postRetryAction\":\"logged-ignore\"}"); SyncFailureHandler handler = factory.create(config); Assert.assertTrue(handler instanceof LoggedIgnoreHandler); }
@Test public void testCreateDeadLetterQueue() throws Exception { JsonValue config = parseJsonString("{\"maxRetries\":0,\"postRetryAction\":\"dead-letter-queue\"}"); SyncFailureHandler handler = factory.create(config); Assert.assertTrue(handler instanceof DeadLetterQueueHandler); }
@Test public void testCreateScript() throws Exception { JsonValue config = parseJsonString("{\"maxRetries\":0,\"postRetryAction\":{\"script\":{\"type\":\"text/javascript\",\"file\":\"script/onSyncFailure.js\"}}}"); SyncFailureHandler handler = factory.create(config); Assert.assertTrue(handler instanceof ScriptedSyncFailureHandler); }