org.reflections.scanners.MemberUsageScanner Java Examples

The following examples show how to use org.reflections.scanners.MemberUsageScanner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckForbiddenMethodsUsage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoDefaultEncoding() throws Exception {
	final Reflections reflections = new Reflections(new ConfigurationBuilder()
		.useParallelExecutor(Runtime.getRuntime().availableProcessors())
		.addUrls(ClasspathHelper.forPackage("org.apache.flink"))
		.addScanners(new MemberUsageScanner()));

	for (ForbiddenCall forbiddenCall : forbiddenCalls) {
		final Set<Member> methodUsages = forbiddenCall.getUsages(reflections);
		methodUsages.removeAll(forbiddenCall.getExclusions());
		assertEquals("Unexpected calls: " + methodUsages, 0, methodUsages.size());
	}
}
 
Example #2
Source File: CheckForbiddenMethodsUsage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoDefaultEncoding() throws Exception {
	final Reflections reflections = new Reflections(new ConfigurationBuilder()
		.useParallelExecutor(Runtime.getRuntime().availableProcessors())
		.addUrls(ClasspathHelper.forPackage("org.apache.flink"))
		.addScanners(new MemberUsageScanner()));

	for (ForbiddenCall forbiddenCall : forbiddenCalls) {
		final Set<Member> methodUsages = forbiddenCall.getUsages(reflections);
		methodUsages.removeAll(forbiddenCall.getExclusions());
		assertEquals("Unexpected calls: " + methodUsages, 0, methodUsages.size());
	}
}
 
Example #3
Source File: CheckForbiddenMethodsUsage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoDefaultEncoding() throws Exception {
	final Reflections reflections = new Reflections(new ConfigurationBuilder()
		.useParallelExecutor(Runtime.getRuntime().availableProcessors())
		.addUrls(ClasspathHelper.forPackage("org.apache.flink"))
		.addScanners(new MemberUsageScanner()));

	for (ForbiddenCall forbiddenCall : forbiddenCalls) {
		final Set<Member> methodUsages = forbiddenCall.getUsages(reflections);
		methodUsages.removeAll(forbiddenCall.getExclusions());
		assertEquals("Unexpected calls: " + methodUsages, 0, methodUsages.size());
	}
}
 
Example #4
Source File: InjectTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIfThereAreUnusedInjections() {
    Reflections reflections = new Reflections("com.sequenceiq",
            new FieldAnnotationsScanner(),
            new TypeAnnotationsScanner(),
            new SubTypesScanner(),
            new MemberUsageScanner());

    Map<String, Set<String>> unusedFields = new HashMap<>();
    reflections.getFieldsAnnotatedWith(Inject.class).forEach(field -> {
        try {
            Set<Member> usages = reflections.getFieldUsage(field);
            if (usages.isEmpty()) {
                String className = field.getDeclaringClass().getName();
                unusedFields.computeIfAbsent(className, key -> new HashSet<>()).add(field.toString());
            }
        } catch (RuntimeException e) {
            // ignore if cannot check fields
        }
    });

    Set<String> fields = new HashSet<>();

    unusedFields.forEach((key, value) -> {
        fields.add(key + ": " + String.join(", ", value));
    });

    Assert.assertTrue(
            String.format("Classes with unused injected fields: %s%s", lineSeparator(), String.join(lineSeparator(), fields)), unusedFields.isEmpty());
}