PlacementFactory { public static PlacementRule getPlacementRule(String ruleStr, Configuration conf) throws ClassNotFoundException { Class<? extends PlacementRule> ruleClass = Class.forName(ruleStr) .asSubclass(PlacementRule.class); LOG.info("Using PlacementRule implementation - " + ruleClass); return ReflectionUtils.newInstance(ruleClass, conf); } private  PlacementFactory(); static PlacementRule getPlacementRule(String ruleStr,
      Configuration conf); static PlacementRule getPlacementRule(
      Class<? extends PlacementRule> ruleClass, Object initArg);  }
@Test(expected = ClassNotFoundException.class) public void testGetNonExistRuleText() throws ClassNotFoundException { final String nonExist = "my.placement.Rule"; PlacementFactory.getPlacementRule(nonExist, null); }
@Test public void testGetExistRuleText() { final String exists = DefaultPlacementRule.class.getCanonicalName(); PlacementRule rule = null; try { rule = PlacementFactory.getPlacementRule(exists, null); } catch (ClassNotFoundException cnfe) { fail("Class should have been found"); } assertNotNull("Rule object is null", rule); assertEquals("Names not equal", rule.getName(), exists); }
@Test public void testGetRuleClass() { PlacementRule rule = PlacementFactory.getPlacementRule( DefaultPlacementRule.class, null); assertNotNull("Rule object is null", rule); rule = PlacementFactory.getPlacementRule( DefaultPlacementRule.class, ""); assertNotNull("Rule object is null", rule); }