aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/junitrunner/java/com/google/testing/junit
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-10-21 16:32:39 +0000
committerGravatar John Cater <jcater@google.com>2016-10-24 19:26:59 +0000
commitbb3a441fefc3b5b6992fb3eb9140710537f2e98a (patch)
tree160ee1be95017c1cacba30cd1ab80b106aba5318 /src/java_tools/junitrunner/java/com/google/testing/junit
parent2bb61c139273b06c77f288e39aefba93e2fc4b3e (diff)
Move junitrunner fake/stub classes from javatests/c/g/testing/junit/runner to java/c/g/testing/junit/runner/sharding/testing. Also:
- Remove Guava dependencies and fix minor style issues in FakeShardingFilters - Fix lint issues in TestSuite[]ModelTest -- MOS_MIGRATED_REVID=136840327
Diffstat (limited to 'src/java_tools/junitrunner/java/com/google/testing/junit')
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/FakeShardingFilters.java78
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/StubShardingEnvironment.java53
2 files changed, 131 insertions, 0 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/FakeShardingFilters.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/FakeShardingFilters.java
new file mode 100644
index 0000000000..8002e0778e
--- /dev/null
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/FakeShardingFilters.java
@@ -0,0 +1,78 @@
+// Copyright 2012 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.sharding.testing;
+
+import com.google.testing.junit.runner.sharding.ShardingFilters;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.runner.Description;
+import org.junit.runner.manipulation.Filter;
+
+/**
+ * Filter factory that includes only descriptions in the set of descriptions
+ * explicitly specified in the constructor.
+ */
+public class FakeShardingFilters extends ShardingFilters {
+ private final Set<Description> descriptionsToRun;
+
+ public FakeShardingFilters(Description... descriptionsToRun) {
+ super(null, null);
+ this.descriptionsToRun = copyOf(descriptionsToRun);
+ }
+
+ @Override
+ public Filter createShardingFilter(Collection<Description> allDescriptions) {
+ return new ExplicitDescriptionFilter(allDescriptions, descriptionsToRun);
+ }
+
+
+ private static class ExplicitDescriptionFilter extends Filter {
+ private final Set<Description> allDescriptions;
+ private final Set<Description> descriptionsToRun;
+
+ private ExplicitDescriptionFilter(
+ Collection<Description> allDescriptions, Set<Description> descriptionsToRun) {
+ this.allDescriptions = copyOf(allDescriptions);
+ this.descriptionsToRun = descriptionsToRun;
+ }
+
+ @Override
+ public boolean shouldRun(Description description) {
+ if (description.isSuite()) {
+ return true;
+ }
+ if (!allDescriptions.contains(description)) {
+ throw new IllegalArgumentException("Not in the suite: " + description);
+ }
+ return descriptionsToRun.contains(description);
+ }
+
+ @Override
+ public String describe() {
+ return "explicit description filter";
+ }
+ }
+
+ private static <T> Set<T> copyOf(T... items) {
+ return copyOf(Arrays.asList(items));
+ }
+
+ private static <T> Set<T> copyOf(Collection<T> items) {
+ return Collections.unmodifiableSet(new HashSet<T>(items));
+ }
+}
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/StubShardingEnvironment.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/StubShardingEnvironment.java
new file mode 100644
index 0000000000..032100dc03
--- /dev/null
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/StubShardingEnvironment.java
@@ -0,0 +1,53 @@
+// Copyright 2012 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.sharding.testing;
+
+import com.google.testing.junit.runner.sharding.ShardingEnvironment;
+
+/**
+ * Stub sharding environment.
+ */
+public class StubShardingEnvironment extends ShardingEnvironment {
+ private boolean shardingEnabled = false;
+
+ @Override
+ public boolean isShardingEnabled() {
+ return shardingEnabled;
+ }
+
+ public void setIsShardingEnabled(boolean shardingEnabled) {
+ this.shardingEnabled = shardingEnabled;
+ }
+
+ @Override
+ public void touchShardFile() {
+ // Noop.
+ }
+
+ @Override
+ public int getShardIndex() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getTotalShards() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getTestShardingStrategy() {
+ throw new UnsupportedOperationException();
+ }
+}