JobShardingStrategyFactory { public static JobShardingStrategy getStrategy(final String jobShardingStrategyClassName) { if (Strings.isNullOrEmpty(jobShardingStrategyClassName)) { return new AverageAllocationJobShardingStrategy(); } try { Class<?> jobShardingStrategyClass = Class.forName(jobShardingStrategyClassName); Preconditions.checkState(JobShardingStrategy.class.isAssignableFrom(jobShardingStrategyClass), String.format("Class [%s] is not job strategy class", jobShardingStrategyClassName)); return (JobShardingStrategy) jobShardingStrategyClass.newInstance(); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException ex) { throw new JobShardingStrategyClassConfigurationException(ex); } }  static JobShardingStrategy getStrategy(final String jobShardingStrategyClassName);  }
@Test public void assertGetDefaultStrategy() { assertThat(JobShardingStrategyFactory.getStrategy(null), instanceOf(AverageAllocationJobShardingStrategy.class)); }
@Test(expected = JobShardingStrategyClassConfigurationException.class) public void assertGetStrategyFailureWhenClassNotFound() { JobShardingStrategyFactory.getStrategy("NotClass"); }
@Test(expected = IllegalStateException.class) public void assertGetStrategyFailureWhenNotStrategyClass() { JobShardingStrategyFactory.getStrategy(Object.class.getName()); }
@Test(expected = JobShardingStrategyClassConfigurationException.class) public void assertGetStrategyFailureWhenStrategyClassInvalid() { JobShardingStrategyFactory.getStrategy(InvalidJobShardingStrategy.class.getName()); }
@Test public void assertGetStrategySuccess() { assertThat(JobShardingStrategyFactory.getStrategy(AverageAllocationJobShardingStrategy.class.getName()), instanceOf(AverageAllocationJobShardingStrategy.class)); }