mirror of
https://github.com/google/nomulus.git
synced 2025-06-26 06:14:54 +02:00
Upgrade to Truth 1.0 (#281)
* Upgrade to Truth 1.0 Refactored fail(...) to assertWithMessage().fail(). Upgraded com.google.monitoring-client family of dependencies to 1.0.6 Also fixed bad use of io.StringIO (on binary buffer) recently introduced to google-java-format-diff.py.
This commit is contained in:
parent
c63a1e559b
commit
7db99e3308
89 changed files with 235 additions and 240 deletions
|
@ -16,7 +16,7 @@ package google.registry.dns.writer.dnsupdate;
|
|||
|
||||
import static com.google.common.io.BaseEncoding.base16;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.newDomainBase;
|
||||
import static google.registry.testing.DatastoreHelper.newHostResource;
|
||||
|
@ -450,9 +450,10 @@ public class DnsUpdateWriterTest {
|
|||
return fixIterator(Record.class, set.rrs());
|
||||
}
|
||||
}
|
||||
assert_().fail(
|
||||
"No record set found for resource '%s' type '%s'",
|
||||
resourceName, Type.string(recordType));
|
||||
assertWithMessage(
|
||||
"No record set found for resource '%s' type '%s'",
|
||||
resourceName, Type.string(recordType))
|
||||
.fail();
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.documentation;
|
||||
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.util.BuildPathUtils.getProjectRoot;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class FlowDocumentationTest {
|
|||
// Don't use Truth's isEqualTo() because the output is huge and unreadable for large files.
|
||||
DocumentationGenerator generator = new DocumentationGenerator();
|
||||
if (!generator.generateMarkdown().equals(goldenMarkdown)) {
|
||||
assert_().fail(UPDATE_INSTRUCTIONS);
|
||||
assertWithMessage(UPDATE_INSTRUCTIONS).fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.mapreduce.inputs;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
|
||||
import static google.registry.model.index.EppResourceIndexBucket.getBucketKey;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
|
@ -290,7 +290,7 @@ public class ChildEntityInputTest {
|
|||
seen.add(reader.next());
|
||||
try {
|
||||
ImmutableObject o = reader.next();
|
||||
assert_().fail("Unexpected element: " + o);
|
||||
assertWithMessage("Unexpected element: %s", o).fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.mapreduce.inputs;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.appengine.tools.mapreduce.Input;
|
||||
import com.google.appengine.tools.mapreduce.InputReader;
|
||||
|
@ -65,7 +65,7 @@ public final class CommitLogManifestInputTest {
|
|||
seen.add(reader.next());
|
||||
try {
|
||||
Key<CommitLogManifest> key = reader.next();
|
||||
assert_().fail("Unexpected element: " + key);
|
||||
assertWithMessage("Unexpected element: %s", key).fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public final class CommitLogManifestInputTest {
|
|||
key = reader.next();
|
||||
seen.add(key);
|
||||
}
|
||||
assert_().fail("Unexpected element: " + key);
|
||||
assertWithMessage("Unexpected element: %s", key).fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public final class CommitLogManifestInputTest {
|
|||
key = reader.next();
|
||||
seen.add(key);
|
||||
}
|
||||
assert_().fail("Unexpected element: " + key);
|
||||
assertWithMessage("Unexpected element: %s", key).fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.mapreduce.inputs;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInput;
|
||||
import static google.registry.mapreduce.inputs.EppResourceInputs.createKeyInput;
|
||||
import static google.registry.model.index.EppResourceIndexBucket.getBucketKey;
|
||||
|
@ -123,7 +123,7 @@ public class EppResourceInputsTest {
|
|||
seen.add(reader.next());
|
||||
try {
|
||||
Key<DomainBase> key = reader.next();
|
||||
assert_().fail("Unexpected element: " + key);
|
||||
assertWithMessage("Unexpected element: %s", key).fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class EppResourceInputsTest {
|
|||
seen.add(reader.next());
|
||||
try {
|
||||
DomainBase domain = reader.next();
|
||||
assert_().fail("Unexpected element: " + domain);
|
||||
assertWithMessage("Unexpected element: %s", domain).fail();
|
||||
} catch (NoSuchElementException expected) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.model;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
|
@ -127,10 +126,10 @@ public abstract class EntityTestCase {
|
|||
// If the field's type was not indexable (because it's not a supported Datastore type) then
|
||||
// this error will be thrown. If we expected no indexing, that's fine. Otherwise, fail.
|
||||
if (indexed || !e.getMessage().endsWith(" is not a supported property type.")) {
|
||||
assert_().fail(String.format("%s was %sindexed", fieldPath, indexed ? "not " : ""));
|
||||
assertWithMessage("%s was %sindexed", fieldPath, indexed ? "not " : "").fail();
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
assert_().fail(String.format("%s (indexed=%b): %s", fieldPath, indexed, e.getMessage()));
|
||||
assertWithMessage("%s (indexed=%b): %s", fieldPath, indexed, e.getMessage()).fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.security;
|
|||
|
||||
import static com.google.common.base.Suppliers.memoize;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.security.JsonHttp.JSON_SAFETY_PREFIX;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -62,7 +62,7 @@ public final class JsonHttpTestUtils {
|
|||
Map<String, Object> json = (Map<String, Object>) JSONValue.parseWithException(jsonText);
|
||||
return json;
|
||||
} catch (ClassCastException | ParseException e) {
|
||||
assert_().fail("Bad JSON: %s\n%s", e.getMessage(), jsonText);
|
||||
assertWithMessage("Bad JSON: %s\n%s", e.getMessage(), jsonText).fail();
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.testing;
|
||||
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
|
||||
import static google.registry.util.ResourceUtils.readResourceUtf8;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
@ -338,7 +338,7 @@ public final class AppEngineRule extends ExternalResource {
|
|||
Set<String> autoIndexes = getIndexXmlStrings(indexFileContent);
|
||||
Set<String> missingIndexes = Sets.difference(autoIndexes, MANUAL_INDEXES);
|
||||
if (!missingIndexes.isEmpty()) {
|
||||
assert_().fail("Missing indexes:\n%s", Joiner.on('\n').join(missingIndexes));
|
||||
assertWithMessage("Missing indexes:\n%s", Joiner.on('\n').join(missingIndexes)).fail();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.testing;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.testing.TestDataHelper.filePath;
|
||||
import static google.registry.testing.TestDataHelper.loadFile;
|
||||
|
||||
|
@ -80,13 +80,12 @@ public class GoldenFileTestHelper {
|
|||
logger.atWarning().log(
|
||||
"Actual routing map was:\n%s\n\nExpected routing map was:\n%s\n",
|
||||
actualValue, expectedValue);
|
||||
assert_()
|
||||
.fail(
|
||||
String.format(
|
||||
UPDATE_INSTRUCTIONS,
|
||||
nomulusCommand,
|
||||
filePath(context, filename),
|
||||
goldenFileDescription));
|
||||
assertWithMessage(
|
||||
UPDATE_INSTRUCTIONS,
|
||||
nomulusCommand,
|
||||
filePath(context, filename),
|
||||
goldenFileDescription)
|
||||
.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
|||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static com.google.common.collect.Multisets.containsOccurrences;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
@ -236,13 +236,11 @@ public class TaskQueueHelper {
|
|||
taskInfos.remove(taskInfos.stream().filter(taskMatcher).findFirst().get());
|
||||
} catch (NoSuchElementException e) {
|
||||
final Map<String, Object> taskMatcherMap = taskMatcher.expected.toMap();
|
||||
assert_()
|
||||
.fail(
|
||||
assertWithMessage(
|
||||
"Task not found in queue %s:\n\n%s\n\nPotential candidate match diffs:\n\n%s",
|
||||
queueName,
|
||||
taskMatcher,
|
||||
taskInfos
|
||||
.stream()
|
||||
taskInfos.stream()
|
||||
.map(
|
||||
input ->
|
||||
prettyPrintEntityDeepDiff(
|
||||
|
@ -250,7 +248,8 @@ public class TaskQueueHelper {
|
|||
Maps.filterKeys(
|
||||
new MatchableTaskInfo(input).toMap(),
|
||||
in(taskMatcherMap.keySet()))))
|
||||
.collect(joining("\n")));
|
||||
.collect(joining("\n")))
|
||||
.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.testing;
|
||||
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.testing.TestLogHandler;
|
||||
|
@ -49,6 +49,6 @@ public final class TestLogHandlerUtils {
|
|||
return;
|
||||
}
|
||||
}
|
||||
assert_().fail(String.format("Log message \"%s\" not found", message));
|
||||
assertWithMessage("Log message \"%s\" not found", message).fail();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.xml;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.util.DiffUtils.prettyPrintXmlDeepDiff;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
|
@ -49,17 +49,15 @@ public class XmlTestUtils {
|
|||
public static void assertXmlEqualsWithMessage(
|
||||
String expected, String actual, String message, String... ignoredPaths) throws Exception {
|
||||
if (!actual.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")) {
|
||||
assert_().fail("XML declaration not found at beginning:\n%s", actual);
|
||||
assertWithMessage("XML declaration not found at beginning:\n%s", actual).fail();
|
||||
}
|
||||
Map<String, Object> expectedMap = toComparableJson(expected, ignoredPaths);
|
||||
Map<String, Object> actualMap = toComparableJson(actual, ignoredPaths);
|
||||
if (!expectedMap.equals(actualMap)) {
|
||||
assert_().fail(String.format(
|
||||
"%s: Expected:\n%s\n\nActual:\n%s\n\nDiff:\n%s\n\n",
|
||||
message,
|
||||
expected,
|
||||
actual,
|
||||
prettyPrintXmlDeepDiff(expectedMap, actualMap, null)));
|
||||
assertWithMessage(
|
||||
"%s: Expected:\n%s\n\nActual:\n%s\n\nDiff:\n%s\n\n",
|
||||
message, expected, actual, prettyPrintXmlDeepDiff(expectedMap, actualMap, null))
|
||||
.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue