ClassLoaderClassInformationRepository implements ClassInformationRepository { @Override public ClassInformation getInformation(String internalClassName) { Validate.notNull(internalClassName); String className = Type.getObjectType(internalClassName).getClassName(); Class<?> cls; try { cls = Class.forName(className, false, classLoader); } catch (ClassNotFoundException cfne) { return null; } boolean interfaceMarker = cls.isInterface(); Class<?>[] interfaceClses = cls.getInterfaces(); List<String> internalInterfaceNames = new ArrayList<>(interfaceClses.length); for (Class<?> interfaceCls : interfaceClses) { internalInterfaceNames.add(Type.getInternalName(interfaceCls)); } String internalSuperClassName; if (interfaceMarker) { internalSuperClassName = Type.getInternalName(Object.class); } else { Class<?> superCls = cls.getSuperclass(); internalSuperClassName = superCls == null ? null : Type.getInternalName(superCls); } return new ClassInformation(internalClassName, internalSuperClassName, internalInterfaceNames, interfaceMarker); } ClassLoaderClassInformationRepository(ClassLoader classLoader); @Override ClassInformation getInformation(String internalClassName);  }
@Test public void mustGetClassInformationForInteger() { ClassInformation info = repo.getInformation("java/lang/Integer"); assertEquals("java/lang/Number", info.getSuperClassName()); assertEquals(1, info.getInterfaces().size()); assertTrue(info.getInterfaces().contains("java/lang/Comparable")); assertFalse(info.isInterface()); }
@Test public void mustGetClassInformationForBoolean() { ClassInformation info = repo.getInformation("java/lang/Boolean"); assertEquals("java/lang/Object", info.getSuperClassName()); assertEquals(2, info.getInterfaces().size()); assertTrue(info.getInterfaces().contains("java/lang/Comparable")); assertTrue(info.getInterfaces().contains("java/io/Serializable")); assertFalse(info.isInterface()); }
@Test public void mustGetClassInformationForObject() { ClassInformation info = repo.getInformation("java/lang/Object"); assertNull(info.getSuperClassName()); assertTrue(info.getInterfaces().isEmpty()); assertFalse(info.isInterface()); }
@Test public void mustGetClassInformationForRunnableFuture() { ClassInformation info = repo.getInformation("java/util/concurrent/RunnableFuture"); assertEquals("java/lang/Object", info.getSuperClassName()); assertEquals(2, info.getInterfaces().size()); assertTrue(info.getInterfaces().contains("java/lang/Runnable")); assertTrue(info.getInterfaces().contains("java/util/concurrent/Future")); assertTrue(info.isInterface()); }
@Test public void mustFailToGetClassInformationForUnknownClass() { ClassInformation info = repo.getInformation("2huowhf9w37fy9fhnwfwfwefasef"); assertNull(info); }