Skip to content

Commit

Permalink
Polish ReflectionUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Nov 27, 2015
1 parent cd9e130 commit a179e3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Expand Up @@ -11,6 +11,7 @@
package org.junit.gen5.commons.util;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

import java.io.File;
import java.lang.reflect.AccessibleObject;
Expand All @@ -26,7 +27,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
* Collection of utilities for working with Java reflection APIs.
Expand Down Expand Up @@ -237,7 +237,7 @@ public static Set<File> getAllClasspathRootDirectories() {
return Arrays.stream(fullClassPath.split(separator))
.filter(part -> !part.endsWith(".jar"))
.map(File::new)
.collect(Collectors.toSet());
.collect(toSet());
// @formatter:on
}

Expand All @@ -251,11 +251,11 @@ public static List<Class<?>> findAllClassesInPackage(String basePackageName, Pre
ReflectionUtils::loadClass).scanForClassesInPackage(basePackageName, classTester);
}

public static List<Class<?>> findInnerClasses(Class<?> clazz, Predicate<Class<?>> predicate) {
public static List<Class<?>> findNestedClasses(Class<?> clazz, Predicate<Class<?>> predicate) {
Preconditions.notNull(clazz, "Class must not be null");
Preconditions.notNull(predicate, "predicate must not be null");

return Arrays.stream(clazz.getDeclaredClasses()).filter(predicate).collect(Collectors.toList());
return Arrays.stream(clazz.getDeclaredClasses()).filter(predicate).collect(toList());
}

public static Optional<Method> findMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
Expand Down Expand Up @@ -327,7 +327,7 @@ private static List<Method> getInterfaceMethods(Class<?> clazz, MethodSortOrder
for (Class<?> ifc : clazz.getInterfaces()) {

List<Method> localMethods = Arrays.stream(ifc.getDeclaredMethods()).filter(Method::isDefault).collect(
Collectors.toList());
toList());

// @formatter:off
List<Method> subInterfaceMethods = getInterfaceMethods(ifc, sortOrder).stream()
Expand Down
Expand Up @@ -164,7 +164,7 @@ private void resolveContainedTestMethods(Class<?> testClass, AbstractTestDescrip
}

private void resolveContainedNestedClasses(Class<?> clazz) {
List<Class<?>> nestedClasses = findInnerClasses(clazz, isNestedTestClass);
List<Class<?>> nestedClasses = findNestedClasses(clazz, isNestedTestClass);
for (Class<?> nestedClass : nestedClasses) {
JUnit5Testable nestedClassTestable = JUnit5Testable.fromClass(nestedClass, engineDescriptor.getUniqueId());
resolveTestable(nestedClassTestable);
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void preBeforeAll(TestExecutionContext testExecutionContext) throws Excep

private List<Object> getObjectsInScope(TestExecutionContext testExecutionContext) {
Predicate<Class<?>> forAllFilter = clazz -> AnnotationUtils.isAnnotated(clazz, ForAll.class);
List<Class<?>> forAllClasses = ReflectionUtils.findInnerClasses(testExecutionContext.getTestClass().get(),
List<Class<?>> forAllClasses = ReflectionUtils.findNestedClasses(testExecutionContext.getTestClass().get(),
forAllFilter);
return forAllClasses.stream().map(clazz -> forAllObjects.get(testExecutionContext, clazz)).collect(
Collectors.toList());
Expand Down

0 comments on commit a179e3e

Please sign in to comment.