Skip to content

Commit c432348

Browse files
committed
Add unit test with json parser for lodash plugin.
1 parent 81bbe84 commit c432348

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lodash-plugin/src/test/java/com/github/underscore/lodash/LodashTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,4 +727,46 @@ public void stackoverflow3() {
727727
int sum = $.sum(Arrays.asList(1, 2, 3, 4));
728728
assertEquals(10, sum);
729729
}
730+
731+
@SuppressWarnings("unchecked")
732+
@Test
733+
public void sqlrujava() {
734+
// http://www.sql.ru/forum/1232207/kak-pravilno-razobrat-json-org-json-simple
735+
String json =
736+
"{"
737+
+ " \"from_excel\":["
738+
+ " {"
739+
+ " \"solution\":\"Fisrt\","
740+
+ " \"num\":\"1\""
741+
+ " },"
742+
+ " {"
743+
+ " \"solution\":\"Second\","
744+
+ " \"num\":\"2\""
745+
+ " },"
746+
+ " {"
747+
+ " \"solution\":\"third\","
748+
+ " \"num\":\"3\""
749+
+ " },"
750+
+ " {"
751+
+ " \"solution\":\"fourth\","
752+
+ " \"num\":\"4\""
753+
+ " },"
754+
+ " {"
755+
+ " \"solution\":\"fifth\","
756+
+ " \"num\":\"5\""
757+
+ " }"
758+
+ " ]"
759+
+ "}";
760+
761+
List<Map<String, Object>> fromExcelData = (List<Map<String, Object>>) $.get(
762+
(Map<String, Object>) $.fromJson(json), "from_excel");
763+
assertEquals("[{solution=Fisrt, num=1}, {solution=Second, num=2}, {solution=third, num=3}, "
764+
+ "{solution=fourth, num=4}, {solution=fifth, num=5}]", fromExcelData.toString());
765+
List<String> solutions = $.map(fromExcelData, new Function1<Map<String, Object>, String>() {
766+
public String apply(Map<String, Object> item) {
767+
return (String) item.get("solution");
768+
}
769+
});
770+
assertEquals("[Fisrt, Second, third, fourth, fifth]", solutions.toString());
771+
}
730772
}

0 commit comments

Comments
 (0)