From b6daafd34183dc1d03e395de65bf6ca58777361f Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Tue, 10 Dec 2019 16:44:59 -0500 Subject: [PATCH] Use TextDiffSubject to compare multi-line text (#406) * Use TextDiffSubject to compare multi-line text It illustrates differences better. Moved TextDiffSubject.java to the common project for sharing. --- common/build.gradle | 14 ++++++++++++++ .../gradle/dependency-locks/testCompile.lockfile | 9 +++++++++ .../testCompileClasspath.lockfile | 9 +++++++++ .../gradle/dependency-locks/testRuntime.lockfile | 10 ++++++++++ .../testRuntimeClasspath.lockfile | 10 ++++++++++ .../dependency-locks/testingCompile.lockfile | 8 ++++++++ .../testingCompileClasspath.lockfile | 8 ++++++++ .../dependency-locks/testingRuntime.lockfile | 8 ++++++++ .../testingRuntimeClasspath.lockfile | 8 ++++++++ .../testing/truth}/TextDiffSubjectTest.java | 16 ++++++++-------- .../registry/testing/truth}/text-diff-actual.txt | 0 .../testing/truth}/text-diff-expected.txt | 0 .../testing/truth}/text-sidebyside-diff.txt | 0 .../testing/truth}/text-unified-diff.txt | 0 .../registry/testing/truth}/TextDiffSubject.java | 2 +- core/build.gradle | 1 + .../gradle/dependency-locks/testRuntime.lockfile | 2 ++ .../testRuntimeClasspath.lockfile | 2 ++ .../tools/GenerateSqlSchemaCommandTest.java | 8 +++----- db/build.gradle | 3 ++- db/gradle/dependency-locks/testCompile.lockfile | 2 -- .../testCompileClasspath.lockfile | 2 -- .../google/registry/sql/flyway/SchemaTest.java | 2 +- 23 files changed, 104 insertions(+), 20 deletions(-) rename {db/src/test/java/google/registry/testing => common/src/test/java/google/registry/testing/truth}/TextDiffSubjectTest.java (86%) rename {db/src/test/resources/google/registry/testing => common/src/test/resources/google/registry/testing/truth}/text-diff-actual.txt (100%) rename {db/src/test/resources/google/registry/testing => common/src/test/resources/google/registry/testing/truth}/text-diff-expected.txt (100%) rename {db/src/test/resources/google/registry/testing => common/src/test/resources/google/registry/testing/truth}/text-sidebyside-diff.txt (100%) rename {db/src/test/resources/google/registry/testing => common/src/test/resources/google/registry/testing/truth}/text-unified-diff.txt (100%) rename {db/src/test/java/google/registry/testing => common/src/testing/java/google/registry/testing/truth}/TextDiffSubject.java (99%) diff --git a/common/build.gradle b/common/build.gradle index bd5b7b4b8..ccce109a6 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -19,12 +19,21 @@ sourceSets { runtimeClasspath += main.output } } + test { + java { + compileClasspath += testing.output + runtimeClasspath += testing.output + } + } } configurations { testingCompile.extendsFrom compile testingRuntime.extendsFrom runtime + testCompile.extendsFrom testingCompile + testRuntime.extendsFrom testingRuntime + // All testing util classes. Other projects may declare dependency as: // testCompile project(path: 'common', configuration: 'testing') testing @@ -49,4 +58,9 @@ dependencies { testingCompile deps['com.google.flogger:flogger'] testingRuntime deps['com.google.flogger:flogger-system-backend'] + testingCompile deps['com.google.truth:truth'] + testingCompile deps['io.github.java-diff-utils:java-diff-utils'] + + testCompile deps['junit:junit'] + testCompile project(':third_party') } diff --git a/common/gradle/dependency-locks/testCompile.lockfile b/common/gradle/dependency-locks/testCompile.lockfile index afe40dd97..87ad3eee7 100644 --- a/common/gradle/dependency-locks/testCompile.lockfile +++ b/common/gradle/dependency-locks/testCompile.lockfile @@ -1,13 +1,22 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 +com.google.flogger:flogger:0.1 com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testCompileClasspath.lockfile b/common/gradle/dependency-locks/testCompileClasspath.lockfile index afe40dd97..87ad3eee7 100644 --- a/common/gradle/dependency-locks/testCompileClasspath.lockfile +++ b/common/gradle/dependency-locks/testCompileClasspath.lockfile @@ -1,13 +1,22 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 +com.google.flogger:flogger:0.1 com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testRuntime.lockfile b/common/gradle/dependency-locks/testRuntime.lockfile index afe40dd97..11dac3337 100644 --- a/common/gradle/dependency-locks/testRuntime.lockfile +++ b/common/gradle/dependency-locks/testRuntime.lockfile @@ -1,13 +1,23 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 +com.google.flogger:flogger-system-backend:0.1 +com.google.flogger:flogger:0.1 com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testRuntimeClasspath.lockfile b/common/gradle/dependency-locks/testRuntimeClasspath.lockfile index afe40dd97..11dac3337 100644 --- a/common/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/common/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -1,13 +1,23 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 +com.google.flogger:flogger-system-backend:0.1 +com.google.flogger:flogger:0.1 com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testingCompile.lockfile b/common/gradle/dependency-locks/testingCompile.lockfile index d8601e75e..87ad3eee7 100644 --- a/common/gradle/dependency-locks/testingCompile.lockfile +++ b/common/gradle/dependency-locks/testingCompile.lockfile @@ -1,6 +1,7 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 com.google.flogger:flogger:0.1 @@ -8,7 +9,14 @@ com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testingCompileClasspath.lockfile b/common/gradle/dependency-locks/testingCompileClasspath.lockfile index d8601e75e..87ad3eee7 100644 --- a/common/gradle/dependency-locks/testingCompileClasspath.lockfile +++ b/common/gradle/dependency-locks/testingCompileClasspath.lockfile @@ -1,6 +1,7 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 com.google.flogger:flogger:0.1 @@ -8,7 +9,14 @@ com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testingRuntime.lockfile b/common/gradle/dependency-locks/testingRuntime.lockfile index 4f95470e5..11dac3337 100644 --- a/common/gradle/dependency-locks/testingRuntime.lockfile +++ b/common/gradle/dependency-locks/testingRuntime.lockfile @@ -1,6 +1,7 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 com.google.flogger:flogger-system-backend:0.1 @@ -9,7 +10,14 @@ com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/common/gradle/dependency-locks/testingRuntimeClasspath.lockfile b/common/gradle/dependency-locks/testingRuntimeClasspath.lockfile index 4f95470e5..11dac3337 100644 --- a/common/gradle/dependency-locks/testingRuntimeClasspath.lockfile +++ b/common/gradle/dependency-locks/testingRuntimeClasspath.lockfile @@ -1,6 +1,7 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. +com.google.auto.value:auto-value-annotations:1.6.3 com.google.code.findbugs:jsr305:3.0.2 com.google.errorprone:error_prone_annotations:2.3.2 com.google.flogger:flogger-system-backend:0.1 @@ -9,7 +10,14 @@ com.google.guava:failureaccess:1.0.1 com.google.guava:guava:28.1-jre com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava com.google.j2objc:j2objc-annotations:1.3 +com.google.truth:truth:1.0 +com.googlecode.java-diff-utils:diffutils:1.3.0 +io.github.java-diff-utils:java-diff-utils:4.0 javax.inject:javax.inject:1 joda-time:joda-time:2.9.2 +junit:junit:4.12 +org.checkerframework:checker-compat-qual:2.5.5 org.checkerframework:checker-qual:2.8.1 org.codehaus.mojo:animal-sniffer-annotations:1.18 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r +org.hamcrest:hamcrest-core:1.3 diff --git a/db/src/test/java/google/registry/testing/TextDiffSubjectTest.java b/common/src/test/java/google/registry/testing/truth/TextDiffSubjectTest.java similarity index 86% rename from db/src/test/java/google/registry/testing/TextDiffSubjectTest.java rename to common/src/test/java/google/registry/testing/truth/TextDiffSubjectTest.java index ef9b73509..4949a1eb8 100644 --- a/db/src/test/java/google/registry/testing/TextDiffSubjectTest.java +++ b/common/src/test/java/google/registry/testing/truth/TextDiffSubjectTest.java @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -package google.registry.testing; +package google.registry.testing.truth; import static com.google.common.io.Resources.getResource; import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.JUnitBackports.assertThrows; -import static google.registry.testing.TextDiffSubject.assertThat; +import static google.registry.testing.truth.TextDiffSubject.assertThat; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.io.Resources; -import google.registry.testing.TextDiffSubject.DiffFormat; +import google.registry.testing.truth.TextDiffSubject.DiffFormat; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.junit.Test; @@ -33,15 +33,15 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class TextDiffSubjectTest { + private static final String RESOURCE_FOLDER = "google/registry/testing/truth/"; // Resources for input data. - private static final String ACTUAL_RESOURCE = "google/registry/testing/text-diff-actual.txt"; - private static final String EXPECTED_RESOURCE = "google/registry/testing/text-diff-expected.txt"; + private static final String ACTUAL_RESOURCE = RESOURCE_FOLDER + "text-diff-actual.txt"; + private static final String EXPECTED_RESOURCE = RESOURCE_FOLDER + "text-diff-expected.txt"; // Resources for expected diff texts. - private static final String UNIFIED_DIFF_RESOURCE = - "google/registry/testing/text-unified-diff.txt"; + private static final String UNIFIED_DIFF_RESOURCE = RESOURCE_FOLDER + "text-unified-diff.txt"; private static final String SIDE_BY_SIDE_DIFF_RESOURCE = - "google/registry/testing/text-sidebyside-diff.txt"; + RESOURCE_FOLDER + "text-sidebyside-diff.txt"; @Test public void unifiedDiff_equal() throws IOException { diff --git a/db/src/test/resources/google/registry/testing/text-diff-actual.txt b/common/src/test/resources/google/registry/testing/truth/text-diff-actual.txt similarity index 100% rename from db/src/test/resources/google/registry/testing/text-diff-actual.txt rename to common/src/test/resources/google/registry/testing/truth/text-diff-actual.txt diff --git a/db/src/test/resources/google/registry/testing/text-diff-expected.txt b/common/src/test/resources/google/registry/testing/truth/text-diff-expected.txt similarity index 100% rename from db/src/test/resources/google/registry/testing/text-diff-expected.txt rename to common/src/test/resources/google/registry/testing/truth/text-diff-expected.txt diff --git a/db/src/test/resources/google/registry/testing/text-sidebyside-diff.txt b/common/src/test/resources/google/registry/testing/truth/text-sidebyside-diff.txt similarity index 100% rename from db/src/test/resources/google/registry/testing/text-sidebyside-diff.txt rename to common/src/test/resources/google/registry/testing/truth/text-sidebyside-diff.txt diff --git a/db/src/test/resources/google/registry/testing/text-unified-diff.txt b/common/src/test/resources/google/registry/testing/truth/text-unified-diff.txt similarity index 100% rename from db/src/test/resources/google/registry/testing/text-unified-diff.txt rename to common/src/test/resources/google/registry/testing/truth/text-unified-diff.txt diff --git a/db/src/test/java/google/registry/testing/TextDiffSubject.java b/common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java similarity index 99% rename from db/src/test/java/google/registry/testing/TextDiffSubject.java rename to common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java index be7f85c8d..f5a91e7a7 100644 --- a/db/src/test/java/google/registry/testing/TextDiffSubject.java +++ b/common/src/testing/java/google/registry/testing/truth/TextDiffSubject.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package google.registry.testing; +package google.registry.testing.truth; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.truth.Truth.assertAbout; diff --git a/core/build.gradle b/core/build.gradle index 32668a2cc..d9b78bca5 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -194,6 +194,7 @@ dependencies { testCompile deps['com.thoughtworks.qdox:qdox'] compile deps['dnsjava:dnsjava'] testCompile deps['io.github.classgraph:classgraph'] + testRuntime deps['io.github.java-diff-utils:java-diff-utils'] testCompile deps['javax.annotation:javax.annotation-api'] testCompile deps['javax.annotation:jsr250-api'] compile deps['javax.inject:javax.inject'] diff --git a/core/gradle/dependency-locks/testRuntime.lockfile b/core/gradle/dependency-locks/testRuntime.lockfile index 2478468d6..077af3a6f 100644 --- a/core/gradle/dependency-locks/testRuntime.lockfile +++ b/core/gradle/dependency-locks/testRuntime.lockfile @@ -141,6 +141,7 @@ commons-logging:commons-logging:1.2 dnsjava:dnsjava:2.1.7 io.dropwizard.metrics:metrics-core:3.1.2 io.github.classgraph:classgraph:4.8.52 +io.github.java-diff-utils:java-diff-utils:4.0 io.grpc:grpc-all:1.17.1 io.grpc:grpc-alts:1.17.1 io.grpc:grpc-auth:1.17.1 @@ -226,6 +227,7 @@ org.codehaus.jackson:jackson-mapper-asl:1.9.13 org.codehaus.mojo:animal-sniffer-annotations:1.18 org.dom4j:dom4j:2.1.1 org.easymock:easymock:3.0 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r org.flywaydb:flyway-core:5.2.4 org.glassfish.jaxb:jaxb-runtime:2.3.1 org.glassfish.jaxb:txw2:2.3.1 diff --git a/core/gradle/dependency-locks/testRuntimeClasspath.lockfile b/core/gradle/dependency-locks/testRuntimeClasspath.lockfile index 2478468d6..077af3a6f 100644 --- a/core/gradle/dependency-locks/testRuntimeClasspath.lockfile +++ b/core/gradle/dependency-locks/testRuntimeClasspath.lockfile @@ -141,6 +141,7 @@ commons-logging:commons-logging:1.2 dnsjava:dnsjava:2.1.7 io.dropwizard.metrics:metrics-core:3.1.2 io.github.classgraph:classgraph:4.8.52 +io.github.java-diff-utils:java-diff-utils:4.0 io.grpc:grpc-all:1.17.1 io.grpc:grpc-alts:1.17.1 io.grpc:grpc-auth:1.17.1 @@ -226,6 +227,7 @@ org.codehaus.jackson:jackson-mapper-asl:1.9.13 org.codehaus.mojo:animal-sniffer-annotations:1.18 org.dom4j:dom4j:2.1.1 org.easymock:easymock:3.0 +org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r org.flywaydb:flyway-core:5.2.4 org.glassfish.jaxb:jaxb-runtime:2.3.1 org.glassfish.jaxb:txw2:2.3.1 diff --git a/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java b/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java index 16f471d40..fd649a71d 100644 --- a/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java @@ -15,9 +15,9 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static google.registry.testing.truth.TextDiffSubject.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.base.Charsets; import com.google.common.io.Files; import com.google.common.io.Resources; import google.registry.persistence.NomulusPostgreSql; @@ -93,9 +93,7 @@ public class GenerateSqlSchemaCommandTest extends CommandTestCase