From d0da502645cd906df5749f0762a11ccc20bb82bc Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 4 Jul 2018 15:44:28 +0900 Subject: [PATCH] Upgrade Truth to 0.42 The 'fail' method is deprecated. Replace it as necessary. The new version includes a dependency on diffutils; add it. Change-Id: I80527c9ea41eb752710bed64cdb1621d4216ee46 --- WORKSPACE | 16 ++++++++---- .../acceptance/AbstractNotificationTest.java | 26 +++++++++++-------- .../common/testing/RangeSubject.java | 5 ++-- java/com/google/gerrit/truth/ListSubject.java | 3 ++- .../google/gerrit/truth/OptionalSubject.java | 5 ++-- lib/truth/BUILD | 8 ++++++ 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index f255ac73ce..4491b12527 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -680,30 +680,36 @@ maven_jar( sha1 = "4785a3c21320980282f9f33d0d1264a69040538f", ) -TRUTH_VERS = "0.40" +TRUTH_VERS = "0.42" maven_jar( name = "truth", artifact = "com.google.truth:truth:" + TRUTH_VERS, - sha1 = "0d74e716afec045cc4a178dbbfde2a8314ae5574", + sha1 = "b5768f644b114e6cf5c3962c2ebcb072f788dcbb", ) maven_jar( name = "truth-java8-extension", artifact = "com.google.truth.extensions:truth-java8-extension:" + TRUTH_VERS, - sha1 = "636e49d675bc28e0b3ae0edd077d6acbbb159166", + sha1 = "4d01dfa5b3780632a3d109e14e101f01d10cce2c", ) maven_jar( name = "truth-liteproto-extension", artifact = "com.google.truth.extensions:truth-liteproto-extension:" + TRUTH_VERS, - sha1 = "21210ac07e5cfbe83f04733f806224a6c0ae4d2d", + sha1 = "c231e6735aa6c133c7e411ae1c1c90b124900a8b", ) maven_jar( name = "truth-proto-extension", artifact = "com.google.truth.extensions:truth-proto-extension:" + TRUTH_VERS, - sha1 = "5a2b504143a5fec2b6be8bce292b3b7577a81789", + sha1 = "c41d22e8b4a61b4171e57c44a2959ebee0091a14", +) + +maven_jar( + name = "diffutils", + artifact = "com.googlecode.java-diff-utils:diffutils:1.3.0", + sha1 = "7e060dd5b19431e6d198e91ff670644372f60fbd", ) # When bumping the easymock version number, make sure to also move powermock to a compatible version diff --git a/java/com/google/gerrit/acceptance/AbstractNotificationTest.java b/java/com/google/gerrit/acceptance/AbstractNotificationTest.java index f2d0f7043d..df57c277e2 100644 --- a/java/com/google/gerrit/acceptance/AbstractNotificationTest.java +++ b/java/com/google/gerrit/acceptance/AbstractNotificationTest.java @@ -14,6 +14,7 @@ package com.google.gerrit.acceptance; +import static com.google.common.truth.Fact.fact; import static com.google.common.truth.Truth.assertAbout; import static com.google.gerrit.extensions.api.changes.RecipientType.BCC; import static com.google.gerrit.extensions.api.changes.RecipientType.CC; @@ -100,7 +101,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest { public FakeEmailSenderSubject notSent() { if (actual().peekMessage() != null) { - fail("a message wasn't sent"); + failWithoutActual(fact("expected message", "sent")); } return this; } @@ -108,7 +109,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest { public FakeEmailSenderSubject sent(String messageType, StagedUsers users) { message = actual().nextMessage(); if (message == null) { - fail("a message was sent"); + failWithoutActual(fact("expected message", "not sent")); } recipients = new HashMap<>(); recipients.put(TO, parseAddresses(message, "To")); @@ -123,11 +124,12 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest { .collect(toList())); this.users = users; if (!message.headers().containsKey("X-Gerrit-MessageType")) { - fail("a message was sent with X-Gerrit-MessageType header"); + failWithoutActual( + fact("expected to have message sent with", "X-Gerrit-MessageType header")); } EmailHeader header = message.headers().get("X-Gerrit-MessageType"); if (!header.equals(new EmailHeader.String(messageType))) { - fail("message of type " + messageType + " was sent; X-Gerrit-MessageType is " + header); + failWithoutActual(fact("expected message of type", messageType)); } // Return a named subject that displays a human-readable table of @@ -191,9 +193,10 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest { private void rcpt(@Nullable RecipientType type, String email, boolean expected) { if (recipients.get(type).contains(email) != expected) { - fail( - expected ? "notifies" : "doesn't notify", - "]\n" + type + ": " + users.emailToName(email) + "\n]"); + failWithoutActual( + fact( + expected ? "notifies" : "doesn't notify", + "[\n" + type + ": " + users.emailToName(email) + "\n]")); } if (expected) { accountedFor.add(email); @@ -219,9 +222,10 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest { } } if (!ok) { - fail( - "was fully tested, missing assertions for: " - + recipientMapToString(unaccountedFor, e -> users.emailToName(e))); + failWithoutActual( + fact( + "expected assertions for", + recipientMapToString(unaccountedFor, e -> users.emailToName(e)))); } return this; } @@ -282,7 +286,7 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest { private void rcpt(@Nullable RecipientType type, NotifyType watch) { if (!users.watchers.containsKey(watch)) { - fail("configured to watch", watch); + failWithoutActual(fact("expected to be configured to watch", watch)); } rcpt(type, users.watchers.get(watch)); } diff --git a/java/com/google/gerrit/extensions/common/testing/RangeSubject.java b/java/com/google/gerrit/extensions/common/testing/RangeSubject.java index b478a7e505..db7f0d1782 100644 --- a/java/com/google/gerrit/extensions/common/testing/RangeSubject.java +++ b/java/com/google/gerrit/extensions/common/testing/RangeSubject.java @@ -14,6 +14,7 @@ package com.google.gerrit.extensions.common.testing; +import static com.google.common.truth.Fact.fact; import static com.google.common.truth.Truth.assertAbout; import com.google.common.truth.FailureMetadata; @@ -51,14 +52,14 @@ public class RangeSubject extends Subject { public void isValid() { isNotNull(); if (!actual().isValid()) { - fail("is valid"); + failWithoutActual(fact("expected", "valid")); } } public void isInvalid() { isNotNull(); if (actual().isValid()) { - fail("is invalid"); + failWithoutActual(fact("expected", "not valid")); } } } diff --git a/java/com/google/gerrit/truth/ListSubject.java b/java/com/google/gerrit/truth/ListSubject.java index cccf51bf12..bd9df303b6 100644 --- a/java/com/google/gerrit/truth/ListSubject.java +++ b/java/com/google/gerrit/truth/ListSubject.java @@ -15,6 +15,7 @@ package com.google.gerrit.truth; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.truth.Fact.fact; import static com.google.common.truth.Truth.assertAbout; import com.google.common.truth.FailureMetadata; @@ -46,7 +47,7 @@ public class ListSubject, E> extends IterableSubject { isNotNull(); List list = getActualList(); if (index >= list.size()) { - fail("has an element at index " + index); + failWithoutActual(fact("expected to have element at index", index)); } return elementAssertThatFunction.apply(list.get(index)); } diff --git a/java/com/google/gerrit/truth/OptionalSubject.java b/java/com/google/gerrit/truth/OptionalSubject.java index f24b5dac96..d91f07b7d2 100644 --- a/java/com/google/gerrit/truth/OptionalSubject.java +++ b/java/com/google/gerrit/truth/OptionalSubject.java @@ -14,6 +14,7 @@ package com.google.gerrit.truth; +import static com.google.common.truth.Fact.fact; import static com.google.common.truth.Truth.assertAbout; import com.google.common.truth.DefaultSubject; @@ -57,7 +58,7 @@ public class OptionalSubject, T> isNotNull(); Optional optional = actual(); if (!optional.isPresent()) { - fail("has a value"); + failWithoutActual(fact("expected to have", "value")); } } @@ -65,7 +66,7 @@ public class OptionalSubject, T> isNotNull(); Optional optional = actual(); if (optional.isPresent()) { - fail("does not have a value"); + failWithoutActual(fact("expected not to have", "value")); } } diff --git a/lib/truth/BUILD b/lib/truth/BUILD index 82cd98a9a6..db5bc489ef 100644 --- a/lib/truth/BUILD +++ b/lib/truth/BUILD @@ -4,6 +4,7 @@ java_library( visibility = ["//visibility:public"], exports = ["@truth//jar"], runtime_deps = [ + ":diffutils", "//lib:guava", "//lib:junit", ], @@ -32,6 +33,13 @@ java_library( ], ) +java_library( + name = "diffutils", + data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"], + visibility = ["//visibility:private"], + exports = ["@diffutils//jar"], +) + java_library( name = "truth-proto-extension", data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"],