Skip to content

Commit

Permalink
Migrate callers of Truth's Subject.failWithRawMessage to Subject.fail…
Browse files Browse the repository at this point in the history
…WithoutActual

Requires the use of Guava 25.1 for Strings.lenientFormat and Truth 0.41 for Subject.failWithoutActual

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=206693099
  • Loading branch information
jlavallee authored and ronshapiro committed Aug 2, 2018
1 parent c105d5d commit 57ee94e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
34 changes: 20 additions & 14 deletions core/src/main/java/com/google/common/truth/MapSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,27 @@ public void containsEntry(@NullableDecl Object key, @NullableDecl Object value)
List<Object> keyList = Lists.newArrayList(key);
List<Object> valueList = Lists.newArrayList(value);
if (hasMatchingToStringPair(actual().keySet(), keyList)) {
failWithRawMessage(
"Not true that %s contains entry <%s (%s)>. However, it does contain keys <%s>.",
actualAsString(),
entry,
objectToTypeName(entry),
countDuplicatesAndAddTypeInfo(
retainMatchingToString(actual().keySet(), keyList /* itemsToCheck */)));
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that %s contains entry <%s (%s)>. However, it does contain keys "
+ "<%s>.",
actualAsString(),
entry,
objectToTypeName(entry),
countDuplicatesAndAddTypeInfo(
retainMatchingToString(actual().keySet(), keyList /* itemsToCheck */)))));
} else if (hasMatchingToStringPair(actual().values(), valueList)) {
failWithRawMessage(
"Not true that %s contains entry <%s (%s)>. However, it does contain values <%s>.",
actualAsString(),
entry,
objectToTypeName(entry),
countDuplicatesAndAddTypeInfo(
retainMatchingToString(actual().values(), valueList /* itemsToCheck */)));
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that %s contains entry <%s (%s)>. However, it does contain values "
+ "<%s>.",
actualAsString(),
entry,
objectToTypeName(entry),
countDuplicatesAndAddTypeInfo(
retainMatchingToString(actual().values(), valueList /* itemsToCheck */)))));
} else if (actual().containsKey(key)) {
Object actualValue = actual().get(key);
/*
Expand Down
51 changes: 30 additions & 21 deletions core/src/main/java/com/google/common/truth/MultimapSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ public void containsEntry(@NullableDecl Object key, @NullableDecl Object value)
Entry<Object, Object> entry = Maps.immutableEntry(key, value);
List<Entry<Object, Object>> entryList = ImmutableList.of(entry);
if (hasMatchingToStringPair(actual().entries(), entryList)) {
failWithRawMessage(
"Not true that %s contains entry <%s (%s)>. However, it does contain entries <%s>",
actualAsString(),
entry,
objectToTypeName(entry),
countDuplicatesAndAddTypeInfo(
retainMatchingToString(actual().entries(), entryList /* itemsToCheck */)));
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that %s contains entry <%s (%s)>. However, it does contain entries "
+ "<%s>",
actualAsString(),
entry,
objectToTypeName(entry),
countDuplicatesAndAddTypeInfo(
retainMatchingToString(
actual().entries(), entryList /* itemsToCheck */)))));
} else if (actual().containsKey(key)) {
failWithoutActual(
simpleFact(
Expand Down Expand Up @@ -204,20 +208,25 @@ public Ordered containsExactlyEntriesIn(Multimap<?, ?> expectedMultimap) {
if (!missing.isEmpty()) {
if (!extra.isEmpty()) {
boolean addTypeInfo = hasMatchingToStringPair(missing.entries(), extra.entries());
failWithRawMessage(
"Not true that %s contains exactly <%s>. "
+ "It is missing <%s> and has unexpected items <%s>",
actualAsString(),
annotateEmptyStringsMultimap(expectedMultimap),
// Note: The usage of countDuplicatesAndAddTypeInfo() below causes entries no longer to
// be grouped by key in the 'missing' and 'unexpected items' parts of the message (we
// still show the actual and expected multimaps in the standard format).
addTypeInfo
? countDuplicatesAndAddTypeInfo(annotateEmptyStringsMultimap(missing).entries())
: countDuplicatesMultimap(annotateEmptyStringsMultimap(missing)),
addTypeInfo
? countDuplicatesAndAddTypeInfo(annotateEmptyStringsMultimap(extra).entries())
: countDuplicatesMultimap(annotateEmptyStringsMultimap(extra)));
failWithoutActual(
simpleFact(
lenientFormat(
"Not true that %s contains exactly <%s>. "
+ "It is missing <%s> and has unexpected items <%s>",
actualAsString(),
annotateEmptyStringsMultimap(expectedMultimap),
// Note: The usage of countDuplicatesAndAddTypeInfo() below causes entries no
// longer to be grouped by key in the 'missing' and 'unexpected items' parts of
// the message (we still show the actual and expected multimaps in the standard
// format).
addTypeInfo
? countDuplicatesAndAddTypeInfo(
annotateEmptyStringsMultimap(missing).entries())
: countDuplicatesMultimap(annotateEmptyStringsMultimap(missing)),
addTypeInfo
? countDuplicatesAndAddTypeInfo(
annotateEmptyStringsMultimap(extra).entries())
: countDuplicatesMultimap(annotateEmptyStringsMultimap(extra)))));
return ALREADY_FAILED;
} else {
failWithBadResults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ public void isEqualTo(@NullableDecl Object expected) {
DiffResult diffResult =
makeDifferencer((Message) expected).diffMessages(actual(), (Message) expected);
if (!diffResult.isMatched()) {
failWithRawMessage(
failureMessage(/* expectedEqual = */ true)
+ "\n"
+ diffResult.printToString(config.reportMismatchesOnly()));
failWithoutActual(
simpleFact(
failureMessage(/* expectedEqual = */ true)
+ "\n"
+ diffResult.printToString(config.reportMismatchesOnly())));
}
}
}
Expand All @@ -316,10 +317,11 @@ public void isNotEqualTo(@NullableDecl Object expected) {
DiffResult diffResult =
makeDifferencer((Message) expected).diffMessages(actual(), (Message) expected);
if (diffResult.isMatched()) {
failWithRawMessage(
failureMessage(/* expectedEqual= */ false)
+ "\n"
+ diffResult.printToString(config.reportMismatchesOnly()));
failWithoutActual(
simpleFact(
failureMessage(/* expectedEqual= */ false)
+ "\n"
+ diffResult.printToString(config.reportMismatchesOnly())));
}
}
}
Expand Down

0 comments on commit 57ee94e

Please sign in to comment.