You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/04/24 10:56:19 UTC
(causeway) 04/05: CAUSEWAY-3989: refactors YAML tests to use Approvals for verification and adds approved YAML outputs
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-3989
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 9ec212d71fd5e10d7e7f809dd187eada4efa6305
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Apr 24 11:49:19 2026 +0100
CAUSEWAY-3989: refactors YAML tests to use Approvals for verification and adds approved YAML outputs
---
.../apache/causeway/commons/io/YamlUtilsTest.java | 22 ++----------
...sTest.toStringUtf8ForList_multiDoc.approved.txt | 39 ++++++++++++++++++++++
...sTest.toStringUtf8ForList_yamlList.approved.txt | 38 +++++++++++++++++++++
3 files changed, 79 insertions(+), 20 deletions(-)
diff --git a/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.java b/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.java
index 9abd229a8e2..ac215027090 100644
--- a/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.java
+++ b/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.java
@@ -19,14 +19,12 @@
package org.apache.causeway.commons.io;
import java.util.List;
-import java.util.stream.Collectors;
import org.approvaltests.Approvals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.causeway.commons.io._TestDomain.Person;
@@ -55,13 +53,7 @@ void toStringUtf8ForList_yamlList() {
val yaml = YamlUtils.toStringUtf8ForList(
List.of(person, person2),
YamlUtils.Marshalling.YAML_LIST);
- assertNotNull(yaml);
-
- val roundTrip = YamlUtils.tryReadAsList(Person.class, DataSource.ofStringUtf8(yaml))
- .valueAsNonNullElseFail();
-
- assertEquals(List.of("sven", "fred"),
- roundTrip.stream().map(Person::getName).collect(Collectors.toList()));
+ Approvals.verify(yaml);
}
@Test
@@ -72,17 +64,7 @@ void toStringUtf8ForList_multiDoc() {
val yaml = YamlUtils.toStringUtf8ForList(
List.of(person, person2),
YamlUtils.Marshalling.MULTI_DOC);
- assertNotNull(yaml);
-
- val docs = yaml.split("(?m)^---\\s*$");
-
- val first = YamlUtils.tryRead(Person.class, docs[0])
- .valueAsNonNullElseFail();
- val second = YamlUtils.tryRead(Person.class, docs[1])
- .valueAsNonNullElseFail();
-
- assertEquals("sven", first.getName());
- assertEquals("fred", second.getName());
+ Approvals.verify(yaml);
}
@Test
diff --git a/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.toStringUtf8ForList_multiDoc.approved.txt b/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.toStringUtf8ForList_multiDoc.approved.txt
new file mode 100644
index 00000000000..3cac21f215c
--- /dev/null
+++ b/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.toStringUtf8ForList_multiDoc.approved.txt
@@ -0,0 +1,39 @@
+name: "sven"
+address:
+ zip: 1234
+ street: "backerstreet"
+additionalAddresses:
+- zip: 23
+ street: "brownstreet"
+- zip: 34
+ street: "bluestreet"
+java8Time:
+ localTime: "17:33:45"
+ localDate: "2007-11-21"
+ localDateTime: "2007-11-21T17:33:45"
+ offsetTime: "17:33:45-02:00"
+ offsetDateTime: "2007-11-21T17:33:45-02:00"
+ zonedDateTime: "2007-11-21T17:33:45+01:00"
+phone:
+ home: "+99 1234"
+ work: null
+---
+name: "fred"
+address:
+ zip: 1234
+ street: "backerstreet"
+additionalAddresses:
+- zip: 23
+ street: "brownstreet"
+- zip: 34
+ street: "bluestreet"
+java8Time:
+ localTime: "17:33:45"
+ localDate: "2007-11-21"
+ localDateTime: "2007-11-21T17:33:45"
+ offsetTime: "17:33:45-02:00"
+ offsetDateTime: "2007-11-21T17:33:45-02:00"
+ zonedDateTime: "2007-11-21T17:33:45+01:00"
+phone:
+ home: "+99 1234"
+ work: null
diff --git a/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.toStringUtf8ForList_yamlList.approved.txt b/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.toStringUtf8ForList_yamlList.approved.txt
new file mode 100644
index 00000000000..935533db17e
--- /dev/null
+++ b/commons/src/test/java/org/apache/causeway/commons/io/YamlUtilsTest.toStringUtf8ForList_yamlList.approved.txt
@@ -0,0 +1,38 @@
+- name: "sven"
+ address:
+ zip: 1234
+ street: "backerstreet"
+ additionalAddresses:
+ - zip: 23
+ street: "brownstreet"
+ - zip: 34
+ street: "bluestreet"
+ java8Time:
+ localTime: "17:33:45"
+ localDate: "2007-11-21"
+ localDateTime: "2007-11-21T17:33:45"
+ offsetTime: "17:33:45-02:00"
+ offsetDateTime: "2007-11-21T17:33:45-02:00"
+ zonedDateTime: "2007-11-21T17:33:45+01:00"
+ phone:
+ home: "+99 1234"
+ work: null
+- name: "fred"
+ address:
+ zip: 1234
+ street: "backerstreet"
+ additionalAddresses:
+ - zip: 23
+ street: "brownstreet"
+ - zip: 34
+ street: "bluestreet"
+ java8Time:
+ localTime: "17:33:45"
+ localDate: "2007-11-21"
+ localDateTime: "2007-11-21T17:33:45"
+ offsetTime: "17:33:45-02:00"
+ offsetDateTime: "2007-11-21T17:33:45-02:00"
+ zonedDateTime: "2007-11-21T17:33:45+01:00"
+ phone:
+ home: "+99 1234"
+ work: null