Skip to content

Commit 6ae2f4f

Browse files
committed
🎨 polishing unit test
1 parent 3efac63 commit 6ae2f4f

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/test/java/io/asfjava/ui/core/schema/UiFormSchemaGeneratorTest.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void testGenerate_textField() throws JsonProcessingException {
3939

4040
Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.title",equalTo("First Name")));
4141
Assert.assertThat(json, hasJsonPath("$.schema.properties.firstName.pattern",equalTo("[a-z]")));
42-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].key",hasSize(1)));
42+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')]",hasSize(1)));
4343
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].description",hasItem("This is a description for your first name field")));
4444
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].placeholder",hasItem("Your first name")));
4545
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='firstName')].validationMessage",hasItem("this is a validation msg")));
@@ -52,7 +52,7 @@ public void testGenerate_Number() throws JsonProcessingException {
5252
UiForm ui = UiFormSchemaGenerator.get().generate(NumberForm.class);
5353
String json = new ObjectMapper().writeValueAsString(ui);
5454
//Assert.assertThat(json, hasJsonPath("$.schema.properties.number.title",equalTo("Number")));
55-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].key",hasSize(1)));
55+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')]",hasSize(1)));
5656
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].description",hasItem("This is a number")));
5757
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].placeholder",hasItem("Number of children")));
5858
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='number')].validationMessage",hasItem("this is a validation msg")));
@@ -68,7 +68,7 @@ public void testGenerate_Password() throws JsonProcessingException {
6868

6969
String json = new ObjectMapper().writeValueAsString(ui);
7070
Assert.assertThat(json, hasJsonPath("$.schema.properties.password.title",equalTo("Password")));
71-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].key",hasSize(1)));
71+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')]",hasSize(1)));
7272
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].description",hasItem("This is password")));
7373
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].placeholder",hasItem("Please set you password")));
7474
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='password')].validationMessage",hasItem("this is a validation msg")));
@@ -83,7 +83,7 @@ public void testGenerate_TextArea() throws JsonProcessingException {
8383

8484
String json = new ObjectMapper().writeValueAsString(ui);
8585
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.title",equalTo("Address")));
86-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].key",hasSize(1)));
86+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')]",hasSize(1)));
8787
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].description",hasItem("This is textarea")));
8888
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].placeholder",hasItem("Fill your address please")));
8989
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].validationMessage",hasItem("this is a validation msg")));
@@ -98,23 +98,20 @@ public void testGenerate_CheckBox() throws JsonProcessingException {
9898
UiForm ui = UiFormSchemaGenerator.get().generate(CheckBoxForm.class);
9999
String json = new ObjectMapper().writeValueAsString(ui);
100100
Assert.assertThat(json, hasJsonPath("$.schema.properties.color.title",equalTo("Color")));
101-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].key",hasSize(1)));
101+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')]",hasSize(1)));
102102
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].multiple",hasItem(false)));
103103
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].required",hasItem(true)));
104-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[0].name",hasItem("Red")));
105-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[0].value",hasItem("red")));
106-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[1].name",hasItem("Blue")));
107-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[1].value",hasItem("blue")));
108-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[2].name",hasItem("Green")));
109-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[2].value",hasItem("green")));
104+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Red')].value",hasItem("red")));
105+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Blue')].value",hasItem("blue")));
106+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Green')].value",hasItem("green")));
110107
}
111108

112109
@Test
113110
public void testGenerate_CheckBox_WithCustomValuesContainer() throws JsonProcessingException {
114111
UiForm ui = UiFormSchemaGenerator.get().generate(CheckBoxForm2.class);
115112
String json = new ObjectMapper().writeValueAsString(ui);
116113
Assert.assertThat(json, hasJsonPath("$.schema.properties.color.title",equalTo("Color")));
117-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].key",hasSize(1)));
114+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')]",hasSize(1)));
118115
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].multiple",hasItem(true)));
119116
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].required",hasItem(false)));
120117
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='color')].titleMap[?(@.name=='Red')].value",hasItem("red")));
@@ -127,7 +124,7 @@ public void testGenerate_RadioBox() throws JsonProcessingException {
127124
UiForm ui = UiFormSchemaGenerator.get().generate(RadioBoxForm.class);
128125
String json = new ObjectMapper().writeValueAsString(ui);
129126
Assert.assertThat(json, hasJsonPath("$.schema.properties.civilState.title",equalTo("Civil State")));
130-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='civilState')].key",hasSize(1)));
127+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='civilState')]",hasSize(1)));
131128
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='civilState')].readOnly",hasItem(false)));
132129
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='civilState')].titleMap[?(@.name=='Maried')].value",hasItem("COMMITTED")));
133130
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='civilState')].titleMap[?(@.name=='Single')].value",hasItem("HAPPY")));
@@ -141,7 +138,7 @@ public void testGenerate_ComboBox() throws JsonProcessingException {
141138

142139
String json = new ObjectMapper().writeValueAsString(ui);
143140
Assert.assertThat(json, hasJsonPath("$.schema.properties.currency.title",equalTo("Currency")));
144-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].key",hasSize(1)));
141+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')]",hasSize(1)));
145142
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].disabled",hasItem(false)));
146143
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].multiple",hasItem(false)));
147144
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='currency')].required",hasItem(true)));
@@ -157,7 +154,7 @@ public void testGenerate_ComboBox_WithCustomValuesContainer() throws JsonProcess
157154

158155
String json = new ObjectMapper().writeValueAsString(ui);
159156
Assert.assertThat(json, hasJsonPath("$.schema.properties.gender.title",equalTo("Gender")));
160-
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].key",hasSize(1)));
157+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')]",hasSize(1)));
161158
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].disabled",hasItem(false)));
162159
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].multiple",hasItem(false)));
163160
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='gender')].required",hasItem(false)));

0 commit comments

Comments
 (0)