aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2017-07-21 19:13:12 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-24 09:51:12 +0200
commit0b370ae035421d081e186bb26d3cc6371db5c66f (patch)
tree50a28adda1faaf18b93d9b79968b4cb257af331f /src/test/java/com/google/devtools/build/lib
parentcfcec545313f79eb5db2c3ba267f1d75825f8749 (diff)
Add an Iterable<Event> Truth subject so that we can easily assert things on an iterable of events without calling into the heavyweight MoreAsserts.
Use that in Skyframe instead of MoreAsserts. Also delete an unused method in MoreAsserts. PiperOrigin-RevId: 162754283
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubject.java37
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubjectFactory.java36
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java16
3 files changed, 73 insertions, 16 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubject.java b/src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubject.java
new file mode 100644
index 0000000000..534c173f35
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubject.java
@@ -0,0 +1,37 @@
+// Copyright 2017 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.devtools.build.lib.testutil;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.Iterables;
+import com.google.common.truth.FailureStrategy;
+import com.google.common.truth.IterableSubject;
+import com.google.common.truth.Subject;
+import com.google.devtools.build.lib.events.Event;
+import javax.annotation.Nullable;
+
+/**
+ * {@link Subject} for {@code Iterable<Event>} that provides an {@link IterableSubject} of {@link
+ * String} objects as opposed to the harder-to-assert-on {@link Event} objects.
+ */
+class EventIterableSubject extends Subject<EventIterableSubject, Iterable<Event>> {
+ EventIterableSubject(FailureStrategy failureStrategy, @Nullable Iterable<Event> actual) {
+ super(failureStrategy, actual);
+ }
+
+ IterableSubject hasEventsThat() {
+ return assertThat(Iterables.transform(actual(), Event::getMessage));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubjectFactory.java b/src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubjectFactory.java
new file mode 100644
index 0000000000..fd46f27642
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubjectFactory.java
@@ -0,0 +1,36 @@
+// Copyright 2017 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.devtools.build.lib.testutil;
+
+import com.google.common.truth.FailureStrategy;
+import com.google.common.truth.IterableSubject;
+import com.google.common.truth.SubjectFactory;
+import com.google.common.truth.Truth;
+import com.google.devtools.build.lib.events.Event;
+
+/**
+ * {@link SubjectFactory} for {@code Iterable<Event>} objects, providing {@link IterableSubject}s of
+ * {@link String} objects for easy asserting.
+ */
+public class EventIterableSubjectFactory
+ extends SubjectFactory<EventIterableSubject, Iterable<Event>> {
+ public static IterableSubject assertThatEvents(Iterable<Event> events) {
+ return Truth.assertAbout(new EventIterableSubjectFactory()).that(events).hasEventsThat();
+ }
+
+ @Override
+ public EventIterableSubject getSubject(FailureStrategy fs, Iterable<Event> eventCollector) {
+ return new EventIterableSubject(fs, eventCollector);
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java b/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java
index 92b00647d6..7564316d1b 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java
@@ -24,7 +24,6 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.events.Event;
@@ -53,21 +52,6 @@ public class MoreAsserts {
assertThat(comp.compare(expected, actual)).isEqualTo(0);
}
- public static <T> void assertContentsAnyOrder(
- Iterable<? extends T> expected, Iterable<? extends T> actual,
- Comparator<? super T> comp) {
- assertThat(actual).hasSize(Iterables.size(expected));
- int i = 0;
- for (T e : expected) {
- for (T a : actual) {
- if (comp.compare(e, a) == 0) {
- i++;
- }
- }
- }
- assertThat(actual).hasSize(i);
- }
-
/**
* Scans if an instance of given class is strongly reachable from a given
* object.