diff options
author | Googler <noreply@google.com> | 2016-09-29 18:24:47 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2016-09-30 08:12:58 +0000 |
commit | 6cd43bbd719b78b7feccd2e11a9c6a4376d3b1e5 (patch) | |
tree | 227009309dc83f17216c3630965270514bce8c73 /src/java_tools/junitrunner/java/com/google/testing/junit/runner | |
parent | 1cbf12f68c80440fe6335900a5da5ef6e6fd3cfa (diff) |
Move some RegExTestCaseFilter from c.g.testing.junit.runner.junit4 to
c.g.testing.junit.junit4.runner.
--
MOS_MIGRATED_REVID=134685188
Diffstat (limited to 'src/java_tools/junitrunner/java/com/google/testing/junit/runner')
3 files changed, 2 insertions, 89 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD index 1969031574..b8887fc58d 100644 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD @@ -9,12 +9,8 @@ package(default_visibility = ["//src:__subpackages__"]) java_library( name = "junit4", - srcs = glob( - ["*.java"], - exclude = ["RegExTestCaseFilter.java"], - ), + srcs = glob(["*.java"]), deps = [ - ":filter", "//src/java_tools/junitrunner/java/com/google/testing/junit/junit4:runner", "//src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal", "//src/java_tools/junitrunner/java/com/google/testing/junit/runner/model", @@ -27,14 +23,6 @@ java_library( ], ) -java_library( - name = "filter", - srcs = ["RegExTestCaseFilter.java"], - deps = [ - "//third_party:junit4", - ], -) - filegroup( name = "srcs", srcs = glob(["**"]), diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java index 7c9338fcd0..0dfd0429cf 100644 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Runner.java @@ -14,6 +14,7 @@ package com.google.testing.junit.runner.junit4; +import com.google.testing.junit.junit4.runner.RegExTestCaseFilter; import com.google.testing.junit.junit4.runner.SuiteTrimmingFilter; import com.google.testing.junit.runner.internal.Stdout; import com.google.testing.junit.runner.model.TestSuiteModel; diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/RegExTestCaseFilter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/RegExTestCaseFilter.java deleted file mode 100644 index 984ba49bfb..0000000000 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/RegExTestCaseFilter.java +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2010 The Bazel Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.testing.junit.runner.junit4; - -import java.util.regex.Pattern; -import org.junit.runner.Description; -import org.junit.runner.manipulation.Filter; - -/** - * Filter that filters out test cases that either matches or does not match a specified regular - * expression. - */ -public final class RegExTestCaseFilter extends Filter { - private static final String TEST_NAME_FORMAT = "%s#%s"; - - private final Pattern pattern; - private final boolean isNegated; - - /** - * Returns a filter that evaluates to {@code true} if the test case description matches - * specified regular expression. Otherwise, returns {@code false}. - */ - public static RegExTestCaseFilter include(String regularExpression) { - return new RegExTestCaseFilter(regularExpression, false); - } - - /** - * Returns a filter that evaluates to {@code false} if the test case description matches - * specified regular expression. Otherwise, returns {@code true}. - */ - public static RegExTestCaseFilter exclude(String regularExpression) { - return new RegExTestCaseFilter(regularExpression, true); - } - - private RegExTestCaseFilter(String regularExpression, boolean isNegated) { - this.isNegated = isNegated; - this.pattern = Pattern.compile(regularExpression); - } - - @Override - public boolean shouldRun(Description description) { - if (description.isSuite()) { - return true; - } - - boolean match = pattern.matcher(formatDescriptionName(description)).find(); - return isNegated ? !match : match; - } - - @Override - public String describe() { - return String.format("%sRegEx[%s]", isNegated ? "NOT " : "", pattern.toString()); - } - - private static String formatDescriptionName(Description description) { - String methodName = (description.getMethodName() == null) ? "" : description.getMethodName(); - - String className = (description.getClassName() == null) ? "" : description.getClassName(); - if (methodName.trim().isEmpty() || className.trim().isEmpty()) { - return description.getDisplayName(); - } - return String.format(TEST_NAME_FORMAT, className, methodName); - } -} |