Improve pretty-print diffing of Datastore entities

This removes the countless lines of the form "[null, []]" in registry_tool diffs
that are an artifact of the way we handle nulls in Objectify.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133409440
This commit is contained in:
mcilwain 2016-09-16 11:43:38 -07:00 committed by Ben McIlwain
parent 841be34d18
commit aa7c05cb8b
6 changed files with 53 additions and 24 deletions

View file

@ -23,7 +23,7 @@ import static com.google.common.collect.Iterables.transform;
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 google.registry.util.DiffUtils.prettyPrintDeepDiff;
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
@ -227,7 +227,7 @@ public class TaskQueueHelper {
.transform(new Function<TaskStateInfo, String>() {
@Override
public String apply(TaskStateInfo input) {
return prettyPrintDeepDiff(
return prettyPrintEntityDeepDiff(
taskMatcherMap,
Maps.filterKeys(
new MatchableTaskInfo(input).toMap(),

View file

@ -15,9 +15,12 @@
package google.registry.util;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
import static google.registry.util.DiffUtils.prettyPrintSetDiff;
import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -57,6 +60,18 @@ public class DiffUtilsTest {
.isEqualTo("\n ADDED: [y, z]\n REMOVED: [b, c]\n FINAL CONTENTS: [a, y, z]");
}
@Test
public void test_emptyToNullCollection_doesntDisplay() {
Map<String, Object> mapA = new HashMap<String, Object>();
mapA.put("a", "jim");
mapA.put("b", null);
Map<String, Object> mapB = new HashMap<String, Object>();
mapB.put("a", "tim");
mapB.put("b", ImmutableSet.of());
// This ensures that it is not outputting a diff of [b -> [null, []].
assertThat(prettyPrintEntityDeepDiff(mapA, mapB)).isEqualTo("a -> [jim, tim]\n");
}
@Test
public void test_prettyPrintSetDiff_addedAndRemovedElements_objects() {
DummyObject a = DummyObject.create("a");

View file

@ -16,7 +16,7 @@ package google.registry.xml;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assert_;
import static google.registry.util.DiffUtils.prettyPrintDeepDiff;
import static google.registry.util.DiffUtils.prettyPrintXmlDeepDiff;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Splitter;
@ -59,7 +59,7 @@ public class XmlTestUtils {
message,
expected,
actual,
prettyPrintDeepDiff(expectedMap, actualMap, null)));
prettyPrintXmlDeepDiff(expectedMap, actualMap, null)));
}
}