APIScanner { public void scan(Reflections manifest) { for (Class<?> apiClass : manifest.getTypesAnnotatedWith(API.class, true)) { if (forClassLoader == apiClass.getClassLoader()) { for (String permissionSetId : apiClass.getAnnotation(API.class).permissionSet()) { PermissionSet permissionSet = permissionProviderFactory.getPermissionSet(permissionSetId); if (permissionSet == null) { permissionSet = new PermissionSet(); permissionProviderFactory.addPermissionSet(permissionSetId, permissionSet); } if (apiClass.isSynthetic()) { permissionSet.addAPIPackage(Reflection.getPackageName(apiClass)); } else { permissionSet.addAPIClass(apiClass); } } } } } APIScanner(StandardPermissionProviderFactory permissionProviderFactory);  APIScanner(StandardPermissionProviderFactory permissionProviderFactory, ClassLoader forClassLoader); void scan(Reflections manifest);  }
@Test public void test() throws Exception { StandardPermissionProviderFactory permissionProviderFactory = mock(StandardPermissionProviderFactory.class); PermissionSet permSet = new PermissionSet(); when(permissionProviderFactory.getPermissionSet(any(String.class))).thenReturn(permSet); ConfigurationBuilder config = new ConfigurationBuilder().addClassLoader(ClasspathHelper.contextClassLoader()).addUrls(ClasspathHelper.forClassLoader()).addScanners(new TypeAnnotationsScanner()); Reflections reflections = new Reflections(config); new APIScanner(permissionProviderFactory).scan(reflections); assertTrue(permSet.isPermitted(APIClass.class)); assertFalse(permSet.isPermitted(NonAPIClassInheritingAPIClass.class)); }