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
This commit is contained in:
David Pursehouse 2018-07-04 15:44:28 +09:00
parent b9287e0a0f
commit d0da502645
6 changed files with 42 additions and 21 deletions

View File

@ -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

View File

@ -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));
}

View File

@ -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<RangeSubject, Comment.Range> {
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"));
}
}
}

View File

@ -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<S extends Subject<S, E>, E> extends IterableSubject {
isNotNull();
List<E> 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));
}

View File

@ -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<S extends Subject<S, ? super T>, T>
isNotNull();
Optional<T> optional = actual();
if (!optional.isPresent()) {
fail("has a value");
failWithoutActual(fact("expected to have", "value"));
}
}
@ -65,7 +66,7 @@ public class OptionalSubject<S extends Subject<S, ? super T>, T>
isNotNull();
Optional<T> optional = actual();
if (optional.isPresent()) {
fail("does not have a value");
failWithoutActual(fact("expected not to have", "value"));
}
}

View File

@ -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"],