munit.internal.junitinterface.GlobFilter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit-interface Show documentation
Show all versions of junit-interface Show documentation
A Java implementation of sbt's test interface for JUnit 4
package munit.internal.junitinterface;
import java.util.ArrayList;
import java.util.regex.Pattern;
import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;
public final class GlobFilter extends Filter
{
private final ArrayList patterns = new ArrayList();
private final RunSettings settings;
public GlobFilter(RunSettings settings, Iterable globPatterns)
{
this.settings = settings;
for(String p : globPatterns) patterns.add(compileGlobPattern(p));
}
@Override
public String describe() {
return "Filters out all tests not matched by the glob patterns";
}
@Override
public boolean shouldRun(Description d)
{
if(d.isSuite()) return true;
String plainName = settings.buildPlainName(d);
for(Pattern p : patterns)
if(p.matcher(plainName).matches()) return true;
return false;
}
private static Pattern compileGlobPattern(String expr) {
String[] a = expr.split("\\*", -1);
StringBuilder b = new StringBuilder();
for(int i=0; i