Skip to content

Commit

Permalink
Polish Javadoc and Filter implementations
Browse files Browse the repository at this point in the history
Issue: #234
  • Loading branch information
sbrannen committed May 28, 2016
1 parent e425ee8 commit bc94538
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Expand Up @@ -15,16 +15,16 @@
import org.junit.gen5.commons.meta.API; import org.junit.gen5.commons.meta.API;


/** /**
* Filters particular tests during test discovery. * A {@link DiscoveryFilter} is applied during test discovery to determine if
* a given container or test should be included in the test plan.
* *
* <p>These filters need to be applied by the {@link TestEngine} during test * <p>{@link TestEngine TestEngines} should apply {@code DiscoveryFilters}
* discovery. * during the test discovery phase.
* *
* @since 5.0 * @since 5.0
* @see EngineDiscoveryRequest * @see EngineDiscoveryRequest
* @see TestEngine * @see TestEngine
*/ */
@API(Experimental) @API(Experimental)
public interface DiscoveryFilter<T> extends Filter<T> { public interface DiscoveryFilter<T> extends Filter<T> {

} }
Expand Up @@ -16,11 +16,24 @@
import org.junit.gen5.engine.DiscoveryFilter; import org.junit.gen5.engine.DiscoveryFilter;


/** /**
* {@link DiscoveryFilter} that is applied to a {@link Class}.
*
* @since 5.0 * @since 5.0
* @see #byNamePattern(String)
*/ */
@API(Experimental) @API(Experimental)
public interface ClassFilter extends DiscoveryFilter<Class<?>> { public interface ClassFilter extends DiscoveryFilter<Class<?>> {


/**
* Create a {@link ClassFilter} based on the supplied class name pattern.
*
* <p>If the fully qualified name of a class matches against the pattern,
* the class will be included in the result set.
*
* @param pattern a regular expression to match against fully qualified
* class names; never {@code null} or empty
* @see Class#getName()
*/
static ClassFilter byNamePattern(String pattern) { static ClassFilter byNamePattern(String pattern) {
return new ClassNameFilter(pattern); return new ClassNameFilter(pattern);
} }
Expand Down
Expand Up @@ -14,24 +14,30 @@


import java.util.regex.Pattern; import java.util.regex.Pattern;


import org.junit.gen5.commons.util.Preconditions;
import org.junit.gen5.engine.FilterResult; import org.junit.gen5.engine.FilterResult;


/** /**
* {@link ClassFilter} that matches fully qualified class names against a
* pattern in the form of a regular expression.
*
* @since 5.0 * @since 5.0
*/ */
class ClassNameFilter implements ClassFilter { class ClassNameFilter implements ClassFilter {


private final Pattern pattern; private final Pattern pattern;


ClassNameFilter(String pattern) { ClassNameFilter(String pattern) {
Preconditions.notBlank(pattern, "pattern must not be null or empty");
this.pattern = Pattern.compile(pattern); this.pattern = Pattern.compile(pattern);
} }


@Override @Override
public FilterResult apply(Class<?> testClass) { public FilterResult apply(Class<?> clazz) {
return includedIf(pattern.matcher(testClass.getName()).matches(), // String name = clazz.getName();
() -> "Test class matches name pattern: " + pattern, // return includedIf(pattern.matcher(name).matches(), //
() -> "Test class does not match name pattern: " + pattern); () -> String.format("Class name [%s] matches pattern: %s", name, pattern), //
() -> String.format("Class name [%s] does not match pattern: %s", name, pattern));
} }


@Override @Override
Expand Down
Expand Up @@ -21,8 +21,8 @@
* A {@code PostDiscoveryFilter} is applied to {@link TestDescriptor TestDescriptors} * A {@code PostDiscoveryFilter} is applied to {@link TestDescriptor TestDescriptors}
* after test discovery. * after test discovery.
* *
* <p>A {@code PostDiscoveryFilter} must not be applied by a {@link TestEngine} * <p>{@link TestEngine TestEngines} must <strong>not</strong> apply
* during test discovery. * {@code PostDiscoveryFilters} during the test discovery phase.
* *
* @since 5.0 * @since 5.0
* @see TestDiscoveryRequest * @see TestDiscoveryRequest
Expand Down

0 comments on commit bc94538

Please sign in to comment.