Skip to content

Commit

Permalink
Minor refactoring in TestExtensionRegistry and JUnit5Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Dec 11, 2015
1 parent c795b9d commit bdaa8b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.junit.gen5.api.Name;
import org.junit.gen5.api.Tag;
import org.junit.gen5.api.extension.ExtendWith;
import org.junit.gen5.api.extension.TestExtension;
import org.junit.gen5.commons.util.StringUtils;
import org.junit.gen5.engine.AbstractTestDescriptor;
import org.junit.gen5.engine.TestTag;
Expand Down Expand Up @@ -57,14 +60,13 @@ protected String determineDisplayName(AnnotatedElement element, String defaultNa

protected TestExtensionRegistry populateNewTestExtensionRegistryFromExtendWith(AnnotatedElement annotatedElement,
TestExtensionRegistry existingTestExtensionRegistry) {
TestExtensionRegistry newTestExtensionRegistry = new TestExtensionRegistry(existingTestExtensionRegistry);
// @formatter:off
findRepeatableAnnotations(annotatedElement, ExtendWith.class).stream()
List<Class<? extends TestExtension>> extensionClasses = findRepeatableAnnotations(annotatedElement, ExtendWith.class).stream()
.map(ExtendWith::value)
.flatMap(Arrays::stream)
.forEach(newTestExtensionRegistry::addExtension);
// @formatter:off
return newTestExtensionRegistry;
.collect(Collectors.toList());
// @formatter:on
return TestExtensionRegistry.newRegistryFrom(existingTestExtensionRegistry, extensionClasses);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
*/
public class TestExtensionRegistry {

public static TestExtensionRegistry newRegistryFrom(TestExtensionRegistry parentRegistry,
List<Class<? extends TestExtension>> extensionClasses) {
TestExtensionRegistry newTestExtensionRegistry = new TestExtensionRegistry(parentRegistry);
extensionClasses.forEach(newTestExtensionRegistry::addExtension);
return newTestExtensionRegistry;
}

private static final List<Class<? extends TestExtension>> defaultExtensionClasses = Collections.unmodifiableList(
Arrays.asList(DisabledCondition.class, TestNameParameterResolver.class));

Expand Down

0 comments on commit bdaa8b7

Please sign in to comment.