From 0b370ae035421d081e186bb26d3cc6371db5c66f Mon Sep 17 00:00:00 2001 From: janakr Date: Fri, 21 Jul 2017 19:13:12 +0200 Subject: Add an Iterable 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 --- .../build/lib/testutil/EventIterableSubject.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubject.java (limited to 'src/test/java/com/google/devtools/build/lib/testutil/EventIterableSubject.java') 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} 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(FailureStrategy failureStrategy, @Nullable Iterable actual) { + super(failureStrategy, actual); + } + + IterableSubject hasEventsThat() { + return assertThat(Iterables.transform(actual(), Event::getMessage)); + } +} -- cgit v1.2.3