### Question:
ReflectionUtils { public static <T> Class<? extends T> forName(String className, Class<T> xface) { Class<?> theCls; try { theCls = Class.forName(className); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } if (!xface.isAssignableFrom(theCls)) { throw new RuntimeException(className + " not " + xface.getName()); } return theCls.asSubclass(xface); }  static Class<? extends T> forName(String className,
                                                 Class<T> xface); static Class<?> getClass(Configuration conf, String name,
                                    Class<?> defaultCls, ClassLoader classLoader); static Class<? extends T> getClass(Configuration conf,
                                                  String name, Class<? extends T> defaultValue,
                                                  Class<T> xface, ClassLoader classLoader); @SuppressWarnings("unchecked") static T newInstance(Class<T> theCls); @SuppressWarnings("unchecked") static T newInstance(String clsName, Class<T> xface);  }### Answer:
@Test public void testForNameClassNotFound() { try { forName( "test.for.name.class.not.found", Object.class); fail("Should fail if class not found"); } catch (RuntimeException re) { assertTrue(re.getCause() instanceof ClassNotFoundException); } }
@Test public void testForNameUnassignable() { try { forName( ClassA.class.getName(), InterfaceB.class); fail("Should fail if class is not assignable"); } catch (RuntimeException re) { assertEquals( ClassA.class.getName() + " not " + InterfaceB.class.getName(), re.getMessage()); } }
@Test public void testForName() throws Exception { Class<? extends InterfaceB> theCls = forName( ClassB.class.getName(), InterfaceB.class); assertEquals(ClassB.class, theCls); }