PostDiscoveryFilter (List<DiscoverySelector> selectors) { return new PostDiscoveryFilter() { @Override public FilterResult apply(TestDescriptor descriptor) { return FilterResult.includedIf(shouldRun(descriptor), () -> descriptor.getDisplayName() + " matches", () -> descriptor.getDisplayName() + " doesn't match"); } private boolean shouldRun(TestDescriptor descriptor) { TestSource source = descriptor.getSource().orElse(null); if (source instanceof MethodSource) { for (DiscoverySelector selector : selectors) { if (selector instanceof MethodSelector && ((MethodSelector)selector).getMethodName().equals(((MethodSource)source).getMethodName()) && (((MethodSelector)selector).getClassName().equals(((MethodSource)source).getClassName()) || inNestedClass((MethodSource)source, createClassSelector(((MethodSelector)selector).getClassName())))) { return true; } } for (DiscoverySelector selector : selectors) { if (selector instanceof ClassSelector && ((ClassSelector)selector).getClassName().equals(((MethodSource)source).getClassName()) || inNestedClass((MethodSource)source, selector)) { return true; } } return false; } return true; } private boolean inNestedClass(MethodSource source, DiscoverySelector selector) { return selector instanceof NestedClassSelector && ((NestedClassSelector)selector).getNestedClassName().equals(source.getClassName()); } }; }