@@ -138,6 +138,42 @@ void migrate() {
138138 Assertions .assertTrue (Files .exists (BASE .resolve (YML .path ())));
139139 }
140140
141+ @ Test
142+ void checkPrettyJsonFormat () throws IOException {
143+ Configurations <MyClass > conf = Configurations .builder (JSON , new JsonDataFormat (true ))
144+ .setBase (BASE )
145+ .build ();
146+
147+ conf .main ();
148+ conf .save ();
149+
150+ Assertions .assertTrue (BASE .resolve (JSON .path ()).toFile ().exists ());
151+ String json = Files .readString (BASE .resolve (JSON .path ()));
152+
153+ // The reason we use .lines() here is because of OS specific differences in line separators (LF & CRLF)
154+ Assertions .assertLinesMatch ("""
155+ {
156+ "name" : "Lilly",
157+ "age" : 20
158+ }
159+ """ .trim ().lines (), json .lines ());
160+ }
161+
162+ @ Test
163+ void checkNonPrettyJsonFormat () throws IOException {
164+ Configurations <MyClass > conf = Configurations .builder (JSON , new JsonDataFormat (false ))
165+ .setBase (BASE )
166+ .build ();
167+
168+ conf .main ();
169+ conf .save ();
170+
171+ Assertions .assertTrue (BASE .resolve (JSON .path ()).toFile ().exists ());
172+ String json = Files .readString (BASE .resolve (JSON .path ()));
173+
174+ Assertions .assertEquals ("{\" name\" :\" Lilly\" ,\" age\" :20}" , json );
175+ }
176+
141177// void example() {
142178// Key<MyClass> mainConfig = Key.builder(Path.of("config.json"), MyClass::new).build();
143179// Configurations<MyClass> conf = Configurations.builder(
@@ -154,7 +190,7 @@ void migrate() {
154190// .build();
155191// }
156192
157- void exampleJacksonBukkit (){
193+ void exampleJacksonBukkit () {
158194 Key <MyClass > mainConfig = Key .builder (Path .of ("config.yml" ), MyClass ::new ).build ();
159195 Configurations .builder (mainConfig , new YamlDataFormat ())
160196 .withClassLoader (this .getClass ().getClassLoader ()) // For minecraft its important to pass the classloader
0 commit comments