ReflectionUtil { public static <T> T getObjWithArgs(String className, Class<T> clazz, ConstructorArgument<?>... args) { return doGetObjWithArgs(className, clazz, args); } private  ReflectionUtil(); static T getObj(String className, Class<T> clazz); static T getObjWithArgs(String className, Class<T> clazz, ConstructorArgument<?>... args); static ConstructorArgument<T> constructorArgument(T value, Class<T> clazz);  }
@Test public void testGetObjWithArgs() { assertEquals(new WithTwoArgConstructor("hello", ImmutableList.of("hello", "world")), ReflectionUtil.getObjWithArgs(WithTwoArgConstructor.class.getName(), WithTwoArgConstructor.class, ReflectionUtil.constructorArgument("hello", String.class), ReflectionUtil.constructorArgument(ImmutableList.of("hello", "world"), List.class))); assertTrue(ReflectionUtil.getObjWithArgs(ArrayList.class.getName(), List.class) instanceof ArrayList); assertEquals(new ArrayList<>(), ReflectionUtil.getObjWithArgs(ArrayList.class.getName(), List.class)); }
@Test(expected = SamzaException.class) public void testGetObjWithArgsZeroArgsNoClass() { ReflectionUtil.getObjWithArgs("not.a.class", Set.class); }
@Test(expected = SamzaException.class) public void testGetObjWithArgsZeroArgsInvalidConstructor() { ReflectionUtil.getObjWithArgs(WithTwoArgConstructor.class.getName(), Object.class); }