-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor util.JsonUtil pretty printing to use no GSON and deduplicate…
… code. #6810
- Loading branch information
1 parent
cb93788
commit aa6b66e
Showing
2 changed files
with
42 additions
and
43 deletions.
There are no files selected for viewing
48 changes: 17 additions & 31 deletions
48
src/main/java/edu/harvard/iq/dataverse/util/json/JsonUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 25 additions & 12 deletions
37
src/test/java/edu/harvard/iq/dataverse/util/json/JsonUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
package edu.harvard.iq.dataverse.util.json; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.EmptySource; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
|
||
public class JsonUtilTest { | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@Test | ||
public void testPrettyPrint() { | ||
JsonUtil jsonUtil = new JsonUtil(); | ||
String nullString = null; | ||
assertEquals(null, JsonUtil.prettyPrint(nullString)); | ||
assertEquals("", JsonUtil.prettyPrint("")); | ||
assertEquals("junk", JsonUtil.prettyPrint("junk")); | ||
assertEquals("{}", JsonUtil.prettyPrint("{}")); | ||
assertEquals("{\n" + " \"foo\": \"bar\"\n" + "}", JsonUtil.prettyPrint("{\"foo\": \"bar\"}")); | ||
public class JsonUtilTest { | ||
|
||
private static Stream<Arguments> testArgs() { | ||
return Stream.of( | ||
Arguments.of(null, null), | ||
Arguments.of("", ""), | ||
Arguments.of("junk", "junk"), | ||
Arguments.of("{}", "\n{\n}"), | ||
Arguments.of("{\"foo\": \"bar\"}", "\n{\n" + " \"foo\": \"bar\"\n" + "}")); | ||
} | ||
|
||
|
||
@ParameterizedTest | ||
@MethodSource("testArgs") | ||
public void testPrettyPrint(String input, String expected) { | ||
assertEquals(expected, JsonUtil.prettyPrint(input)); | ||
} | ||
|
||
} |