MetaInfReader { @VisibleForTesting @SuppressWarnings("unchecked") static <T> Class<T> classForNameOrNull(String name) { try { return (Class<T>) Class.forName(name); } catch (ClassNotFoundException e) { return null; } } private  MetaInfReader(); static Stream<Class<T>> readClasses(String fileName); static Stream<String> readLines(String fileName);  }
@Test public void testClassForName() { String name = "java.lang.Object"; Class<?> clazz = MetaInfReader.classForNameOrNull(name); assertEquals("Object class should have worked", Object.class, clazz); }
@Test public void testClassForNameNonExistent() { String name = "not.a.real.Type"; Class<?> clazz = MetaInfReader.classForNameOrNull(name); assertNull("No class should exist with name '" + name + "'", clazz); }
@Test public void testClassForNamePrivateInner() { String name = Inner.class.getName(); Class<?> clazz = MetaInfReader.classForNameOrNull(name); assertEquals("A private inner class should be accessible", Inner.class, clazz); }