From 7eef51352cc4314abfd9e4c32645c1357d6862d8 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Mon, 8 Jul 2024 20:44:29 -0300 Subject: [PATCH] Introduce ApprovalTests (https://approvaltests.com/) - It opens a diff window when comparing Strings and File contents --- pom.xml | 10 ++++++++++ ...roperties.testStoreOutputStream.approved.txt | 17 +++++++++++++++++ .../codejive/properties/PackageSettings.java | 12 ++++++++++++ .../org/codejive/properties/TestProperties.java | 3 ++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/test/approvals/org/codejive/properties/TestProperties.testStoreOutputStream.approved.txt create mode 100644 src/test/java/org/codejive/properties/PackageSettings.java diff --git a/pom.xml b/pom.xml index 829a016..e8d64c6 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,7 @@ 3.21.0 2.12.2 1.7 + 24.2.0 @@ -49,6 +50,12 @@ ${assertj.version} test + + com.approvaltests + approvaltests + ${approvaltests.version} + test + @@ -66,6 +73,9 @@ .gitignore .gitattributes + + src/test/approvals/** + diff --git a/src/test/approvals/org/codejive/properties/TestProperties.testStoreOutputStream.approved.txt b/src/test/approvals/org/codejive/properties/TestProperties.testStoreOutputStream.approved.txt new file mode 100644 index 0000000..7c6e49c --- /dev/null +++ b/src/test/approvals/org/codejive/properties/TestProperties.testStoreOutputStream.approved.txt @@ -0,0 +1,17 @@ +#comment1 +# comment2 + +! comment3 +one=simple +two=value containing spaces +# another comment +! and a comment +! block +three=and escapes\n\t\r\f +\ with\ spaces = everywhere +altsep:value +multiline = one \ + two \ + three +key.4 = \u1234\u1234 +# final comment diff --git a/src/test/java/org/codejive/properties/PackageSettings.java b/src/test/java/org/codejive/properties/PackageSettings.java new file mode 100644 index 0000000..b7a4e3c --- /dev/null +++ b/src/test/java/org/codejive/properties/PackageSettings.java @@ -0,0 +1,12 @@ +package org.codejive.properties; + +/** + * This class is used by the ApprovalTests framework + * + * @see ApprovalTests + * Configuration + */ +public class PackageSettings { + public static String ApprovalBaseDirectory = "../approvals"; +} diff --git a/src/test/java/org/codejive/properties/TestProperties.java b/src/test/java/org/codejive/properties/TestProperties.java index c74449b..dca5dce 100644 --- a/src/test/java/org/codejive/properties/TestProperties.java +++ b/src/test/java/org/codejive/properties/TestProperties.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; +import org.approvaltests.Approvals; import org.junit.jupiter.api.Test; public class TestProperties { @@ -124,7 +125,7 @@ void testStoreOutputStream() throws IOException, URISyntaxException { Properties p = Properties.loadProperties(f); ByteArrayOutputStream os = new ByteArrayOutputStream(); p.store(os); - assertThat(os.toString()).isEqualTo(readAll(f)); + Approvals.verify(os.toString()); } @Test