Skip to content

Commit

Permalink
Merge pull request #51 from jbehavesupport/discovery-abstract
Browse files Browse the repository at this point in the history
Improve JUnit5 discovery to exclude abstract classes.
  • Loading branch information
paveljandejsek authored Dec 22, 2023
2 parents ed3e75a + 31eacd6 commit bafab7e
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
import org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver;

import java.util.function.Predicate;

import static java.lang.reflect.Modifier.isAbstract;

public class JBehaveDiscoverer {

public EngineDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
Expand All @@ -37,9 +41,21 @@ public EngineDescriptor discover(EngineDiscoveryRequest discoveryRequest, Unique

private EngineDiscoveryRequestResolver<TestDescriptor> getResolver(EngineDiscoveryRequest discoveryRequest, UniqueId engineId) {
return EngineDiscoveryRequestResolver.builder()
.addClassContainerSelectorResolver(JUnit5Stories.class::isAssignableFrom)
.addClassContainerSelectorResolver(getJBehaveClassSelector())
.addSelectorResolver(new JBehaveSelectorResolver(discoveryRequest, engineId))
.build();
}

private static Predicate<Class<?>> getJBehaveClassSelector() {
return isCorrectClass().and(isNotAbstract());
}

private static Predicate<Class<?>> isNotAbstract() {
return clazz -> !isAbstract(clazz.getModifiers());
}

private static Predicate<Class<?>> isCorrectClass() {
return JUnit5Stories.class::isAssignableFrom;
}

}

0 comments on commit bafab7e

Please sign in to comment.