RetryPolicyFactory { public static RetryPolicy create(String policyValue) { if (policyValue != null) { if (policyValue.indexOf(":") != -1) { String[] splits = policyValue.split(":"); if (splits != null && splits.length == 2) { String type = splits[0]; String value = splits[1]; if (type != null && !"".equals(type.trim()) && value != null && !"".equals(value.trim())) { switch (type.trim()) { case "1": return new FrequencySpecifiedRetryPolicy(value.trim()); default: break; } } } } } throw new IllegalArgumentException(String.format("Unknown retry policy for value %s", policyValue)); }  static RetryPolicy create(String policyValue);  }
@Test(expected = IllegalArgumentException.class) public void testInvalid1() throws Exception { RetryPolicyFactory.create(null); }
@Test(expected = IllegalArgumentException.class) public void testInvalid2() throws Exception { RetryPolicyFactory.create("2"); }
@Test(expected = IllegalArgumentException.class) public void testInvalid3() throws Exception { RetryPolicyFactory.create("2:"); }
@Test(expected = IllegalArgumentException.class) public void testInvalid4() throws Exception { RetryPolicyFactory.create("2: "); }
@Test(expected = IllegalArgumentException.class) public void testInvalid5() throws Exception { RetryPolicyFactory.create(" :1"); }
@Test public void testValid() throws Exception { RetryPolicy policy = RetryPolicyFactory.create("1:[1,2]"); Assert.assertTrue(policy instanceof FrequencySpecifiedRetryPolicy); Assert.assertEquals(2, policy.getRetryTimes()); }