Skip to content

Commit 2fbc151

Browse files
authored
Added unit tests toJson and toXml.
1 parent 9374f4b commit 2fbc151

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/test/java/com/github/underscore/LodashTest.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ void fetchGet() {
499499
void downloadUrl() throws IOException {
500500
long result =
501501
U.downloadUrl(
502-
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json", "test.json");
502+
"https://support.oneskyapp.com/hc/en-us/article_attachments/202761627/example_1.json",
503+
"test.json");
503504
assertEquals(65, result);
504505
}
505506

@@ -643,6 +644,39 @@ void fetchWrongUrlWithRetry() {
643644
UnsupportedOperationException.class, () -> U.fetch("ttt", 30000, 30000, 1, 100));
644645
}
645646

647+
@Test
648+
void toJson() {
649+
Map<String, Object> map = U.newLinkedHashMap();
650+
map.put(null, 3);
651+
assertEquals("{\n \"null\": 3\n}", U.toJson(map));
652+
Map<Object, Object> map2 = U.newLinkedHashMap();
653+
map2.put(1, 3);
654+
assertEquals("{\n \"1\": 3\n}", U.toJson(map2));
655+
Map<Object, Object> map3 = U.newLinkedHashMap();
656+
map3.put(true, 3);
657+
assertEquals("{\n \"true\": 3\n}", U.toJson(map3));
658+
}
659+
660+
@Test
661+
void toXml() {
662+
Map<String, Object> map = U.newLinkedHashMap();
663+
map.put(null, 3);
664+
assertEquals(
665+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<null number=\"true\">3</null>",
666+
U.toXml(map));
667+
Map<Object, Object> map2 = U.newLinkedHashMap();
668+
map2.put(1, 3);
669+
assertEquals(
670+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
671+
+ "<__GE__ number=\"true\">3</__GE__>",
672+
U.toXml(map2));
673+
Map<Object, Object> map3 = U.newLinkedHashMap();
674+
map3.put(true, 3);
675+
assertEquals(
676+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<true number=\"true\">3</true>",
677+
U.toXml(map3));
678+
}
679+
646680
@Test
647681
void xmlToJson() {
648682
assertEquals(
@@ -662,8 +696,9 @@ void xmlToJson() {
662696
+ " ],\n"
663697
+ " \"#omit-xml-declaration\": \"yes\"\n"
664698
+ "}",
665-
U.xmlToJson("<root><element>1</element><element>2</element></root>",
666-
Json.JsonStringBuilder.Step.TWO_SPACES));
699+
U.xmlToJson(
700+
"<root><element>1</element><element>2</element></root>",
701+
Json.JsonStringBuilder.Step.TWO_SPACES));
667702
assertEquals(
668703
"{\n"
669704
+ " \"root\": [\n"

0 commit comments

Comments
 (0)