Skip to content
Permalink
Browse files

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.
  • Loading branch information
weiminyu committed Dec 10, 2019
1 parent f7b243e commit 3aad8b6aa7ba8d1ecc5b97aae9d9ced842a7bdcb
Showing with 104 additions and 20 deletions.
  1. +14 −0 common/build.gradle
  2. +9 −0 common/gradle/dependency-locks/testCompile.lockfile
  3. +9 −0 common/gradle/dependency-locks/testCompileClasspath.lockfile
  4. +10 −0 common/gradle/dependency-locks/testRuntime.lockfile
  5. +10 −0 common/gradle/dependency-locks/testRuntimeClasspath.lockfile
  6. +8 −0 common/gradle/dependency-locks/testingCompile.lockfile
  7. +8 −0 common/gradle/dependency-locks/testingCompileClasspath.lockfile
  8. +8 −0 common/gradle/dependency-locks/testingRuntime.lockfile
  9. +8 −0 common/gradle/dependency-locks/testingRuntimeClasspath.lockfile
  10. +8 −8 ...e/registry/testing → common/src/test/java/google/registry/testing/truth}/TextDiffSubjectTest.java
  11. 0 .../registry/testing → common/src/test/resources/google/registry/testing/truth}/text-diff-actual.txt
  12. 0 ...egistry/testing → common/src/test/resources/google/registry/testing/truth}/text-diff-expected.txt
  13. 0 ...istry/testing → common/src/test/resources/google/registry/testing/truth}/text-sidebyside-diff.txt
  14. 0 ...registry/testing → common/src/test/resources/google/registry/testing/truth}/text-unified-diff.txt
  15. +1 −1 ...le/registry/testing → common/src/testing/java/google/registry/testing/truth}/TextDiffSubject.java
  16. +1 −0 core/build.gradle
  17. +2 −0 core/gradle/dependency-locks/testRuntime.lockfile
  18. +2 −0 core/gradle/dependency-locks/testRuntimeClasspath.lockfile
  19. +3 −5 core/src/test/java/google/registry/tools/GenerateSqlSchemaCommandTest.java
  20. +2 −1 db/build.gradle
  21. +0 −2 db/gradle/dependency-locks/testCompile.lockfile
  22. +0 −2 db/gradle/dependency-locks/testCompileClasspath.lockfile
  23. +1 −1 db/src/test/java/google/registry/sql/flyway/SchemaTest.java
@@ -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')
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,14 +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
@@ -1,14 +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
@@ -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
@@ -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
@@ -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 @@
@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 {
@@ -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;
@@ -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']
@@ -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
@@ -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
@@ -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 void testDockerPostgresql() throws Exception {
public void validateGeneratedSchemaIsSameAsSchemaInFile() throws Exception {
runCommand(
"--start_postgresql", "--out_file=" + tmp.getRoot() + File.separatorChar + "schema.sql");
assertThat(Files.readLines(new File(tmp.getRoot(), "schema.sql"), Charsets.UTF_8))
.isEqualTo(
Resources.readLines(
Resources.getResource("sql/schema/db-schema.sql.generated"), Charsets.UTF_8));
assertThat(new File(tmp.getRoot(), "schema.sql").toURI().toURL())
.hasSameContentAs(Resources.getResource("sql/schema/db-schema.sql.generated"));
}
}
@@ -152,10 +152,11 @@ dependencies {
testRuntime deps['com.google.flogger:flogger-system-backend']
testCompile deps['com.google.guava:guava']
testCompile deps['com.google.truth:truth']
testCompile deps['io.github.java-diff-utils:java-diff-utils']
testRuntime deps['io.github.java-diff-utils:java-diff-utils']
testCompile deps['junit:junit']
testCompile deps['org.testcontainers:postgresql']
testCompile deps['org.testcontainers:testcontainers']
testCompile project(path: ':common', configuration: 'testing')
testCompile project(':third_party')
}

@@ -13,7 +13,6 @@ com.google.truth:truth:1.0
com.googlecode.java-diff-utils:diffutils:1.3.0
com.kohlschutter.junixsocket:junixsocket-common:2.0.4
com.kohlschutter.junixsocket:junixsocket-native-common:2.0.4
io.github.java-diff-utils:java-diff-utils:4.0
javax.activation:javax.activation-api:1.2.0
javax.annotation:javax.annotation-api:1.3.2
javax.xml.bind:jaxb-api:2.3.1
@@ -24,7 +23,6 @@ org.apache.commons:commons-compress:1.19
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.flywaydb:flyway-core:5.2.4
org.hamcrest:hamcrest-core:1.3
org.jetbrains:annotations:17.0.0
@@ -13,7 +13,6 @@ com.google.truth:truth:1.0
com.googlecode.java-diff-utils:diffutils:1.3.0
com.kohlschutter.junixsocket:junixsocket-common:2.0.4
com.kohlschutter.junixsocket:junixsocket-native-common:2.0.4
io.github.java-diff-utils:java-diff-utils:4.0
javax.activation:javax.activation-api:1.2.0
javax.annotation:javax.annotation-api:1.3.2
javax.xml.bind:jaxb-api:2.3.1
@@ -24,7 +23,6 @@ org.apache.commons:commons-compress:1.19
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.flywaydb:flyway-core:5.2.4
org.hamcrest:hamcrest-core:1.3
org.jetbrains:annotations:17.0.0
@@ -15,7 +15,7 @@
package google.registry.sql.flyway;

import static com.google.common.truth.Truth.assertThat;
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.io.Resources;

0 comments on commit 3aad8b6

Please sign in to comment.
You can’t perform that action at this time.