File tree Expand file tree Collapse file tree 4 files changed +76
-0
lines changed
approvaltests-tests/src/test/java/org/approvaltests
src/main/java/org/approvaltests Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .approvaltests ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import java .time .Instant ;
6+
7+ public class JsonXstreamApprovalTest
8+ {
9+ @ Test
10+ public void testBasicFormatting ()
11+ {
12+ Circular c = new Circular ();
13+ JsonXtreamApprovals .verifyAsJson (c );
14+ }
15+
16+ public static class Circular {
17+ Circular parent ;
18+ String label ;
19+
20+ public Circular () {
21+ this .parent = this ;
22+ this .label = "Label" ;
23+ }
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ {"org.approvaltests.JsonXstreamApprovalTest$Circular" : {
2+ "parent" : {
3+ "@reference" : " .."
4+ },
5+ "label" : " Label"
6+ }}
Original file line number Diff line number Diff line change 1919 <artifactId >approvaltests-util</artifactId >
2020 <version >${project.parent.version} </version >
2121 </dependency >
22+ <dependency >
23+ <groupId >org.apache.camel</groupId >
24+ <artifactId >camel-xstream</artifactId >
25+ <version >2.21.0</version >
26+ </dependency >
2227 <dependency >
2328 <groupId >org.testng</groupId >
2429 <artifactId >testng</artifactId >
2530 <version >7.5</version >
2631 <optional >true</optional >
2732 </dependency >
33+ <dependency >
34+ <groupId >com.thoughtworks.xstream</groupId >
35+ <artifactId >xstream</artifactId >
36+ <version >1.4.19</version >
37+ <optional >true</optional >
38+ </dependency >
39+ <dependency >
40+ <groupId >org.codehaus.jettison</groupId >
41+ <artifactId >jettison</artifactId >
42+ <version >1.5.1</version >
43+ <optional >true</optional >
44+ </dependency >
2845 <dependency >
2946 <groupId >com.google.code.gson</groupId >
3047 <artifactId >gson</artifactId >
Original file line number Diff line number Diff line change 1+ package org .approvaltests ;
2+
3+ import com .thoughtworks .xstream .XStream ;
4+ import com .thoughtworks .xstream .io .json .JettisonMappedXmlDriver ;
5+ import com .thoughtworks .xstream .io .json .JsonHierarchicalStreamDriver ;
6+ import com .thoughtworks .xstream .io .xml .PrettyPrintWriter ;
7+ import org .approvaltests .core .Options ;
8+
9+ import java .io .BufferedOutputStream ;
10+ import java .io .BufferedWriter ;
11+ import java .io .StringWriter ;
12+
13+ public class JsonXtreamApprovals
14+ {
15+ public static void verifyAsJson (Object o )
16+ {
17+ verifyAsJson (o , new Options ());
18+ }
19+ public static void verifyAsJson (Object o , Options options )
20+ {
21+ Approvals .verify (asJson (o ), options .forFile ().withExtension (".json" ));
22+ }
23+ public static String asJson (Object o )
24+ {
25+ XStream xstream = new XStream (new JsonHierarchicalStreamDriver ());
26+ return xstream .toXML (o );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments