2020import static org .assertj .core .api .Assertions .assertThat ;
2121
2222import java .io .StringReader ;
23+ import java .util .Arrays ;
24+ import java .util .Collections ;
25+ import java .util .List ;
2326import java .util .Optional ;
27+
2428import org .junit .jupiter .api .Test ;
2529
2630class JsonConfigTest {
@@ -32,4 +36,83 @@ void shouldUseATableAsASection() {
3236
3337 assertThat (config .get ("cheeses" , "selected" )).isEqualTo (Optional .of ("brie" ));
3438 }
39+
40+ @ Test
41+ void ensureCanReadListOfStrings () {
42+ String raw = String .join ("" , "" ,
43+ "{" ,
44+ "`relay`: {" ,
45+ "`configs`: [`2`, `{\\ `browserName\\ `: \\ `chrome\\ `}`]" ,
46+ "}" ,
47+ "}"
48+ ).replace ("`" , "\" " );
49+ Config config = new JsonConfig (new StringReader (raw ));
50+
51+ List <String > expected = Arrays .asList (
52+ "2" ,
53+ "{\" browserName\" : \" chrome\" }"
54+ );
55+ Optional <List <String >> content = config .getAll ("relay" , "configs" );
56+ assertThat (content ).isEqualTo (Optional .of (expected ));
57+ }
58+
59+ @ Test
60+ void shouldContainConfigFromArrayOfTables () {
61+ String raw = String .join ("" , "" ,
62+ "{" ,
63+ "`cheeses`: {" ,
64+ "`default`: `manchego`," ,
65+ "`type`: [" ,
66+ "{" ,
67+ "`name`: `soft cheese`," ,
68+ "`default`: `brie`" ,
69+ "}," ,
70+ "{" ,
71+ "`name`: `Medium-hard cheese`," ,
72+ "`default`: `Emmental`" ,
73+ "}" ,
74+ "]" ,
75+ "}" ,
76+ "}"
77+ ).replace ("`" , "\" " );
78+ Config config = new JsonConfig (new StringReader (raw ));
79+
80+ assertThat (config .get ("cheeses" , "default" )).isEqualTo (Optional .of ("manchego" ));
81+
82+ List <String > expected =
83+ Arrays .asList (
84+ "default=\" brie\" " , "name=\" soft cheese\" " ,
85+ "default=\" Emmental\" " , "name=\" Medium-hard cheese\" " );
86+ assertThat (config .getAll ("cheeses" , "type" ).orElse (Collections .emptyList ()))
87+ .isEqualTo (expected );
88+ assertThat (config .getAll ("cheeses" , "type" ).orElse (Collections .emptyList ()).subList (0 , 2 ))
89+ .isEqualTo (expected .subList (0 , 2 ));
90+ }
91+
92+ @ Test
93+ void ensureCanReadListOfMaps () {
94+ String raw = String .join ("" , "" ,
95+ "{" ,
96+ "`node`: {" ,
97+ "`detect-drivers`: false," ,
98+ "`driver-configuration`: [" ,
99+ "{" ,
100+ "`display-name`: `htmlunit`," ,
101+ "`stereotype`: {" ,
102+ "`browserName`: `htmlunit`," ,
103+ "`browserVersion`: `chrome`" ,
104+ "}" ,
105+ "}" ,
106+ "]" ,
107+ "}" ,
108+ "}"
109+ ).replace ("`" , "\" " );
110+ Config config = new JsonConfig (new StringReader (raw ));
111+ List <String > expected = Arrays .asList (
112+ "display-name=\" htmlunit\" " ,
113+ "stereotype={\" browserName\" : \" htmlunit\" ,\" browserVersion\" : \" chrome\" }"
114+ );
115+ Optional <List <String >> content = config .getAll ("node" , "driver-configuration" );
116+ assertThat (content ).isEqualTo (Optional .of (expected ));
117+ }
35118}
0 commit comments