|
15 | 15 | */
|
16 | 16 | package org.everit.json.schema;
|
17 | 17 |
|
18 |
| -import nl.jqno.equalsverifier.EqualsVerifier; |
19 |
| -import nl.jqno.equalsverifier.Warning; |
| 18 | +import static org.everit.json.schema.ObjectComparator.deepEquals; |
| 19 | +import static org.everit.json.schema.TestSupport.buildWithLocation; |
| 20 | +import static org.junit.Assert.assertTrue; |
| 21 | + |
| 22 | +import java.util.Optional; |
| 23 | + |
20 | 24 | import org.everit.json.schema.loader.SchemaLoader;
|
21 | 25 | import org.json.JSONObject;
|
22 | 26 | import org.junit.Assert;
|
23 | 27 | import org.junit.Test;
|
24 | 28 |
|
25 |
| -import java.util.Optional; |
26 |
| - |
27 |
| -import static org.everit.json.schema.TestSupport.buildWithLocation; |
28 |
| -import static org.junit.Assert.assertTrue; |
| 29 | +import nl.jqno.equalsverifier.EqualsVerifier; |
| 30 | +import nl.jqno.equalsverifier.Warning; |
29 | 31 |
|
30 | 32 | public class StringSchemaTest {
|
31 | 33 |
|
@@ -124,39 +126,48 @@ public void equalsVerifier() {
|
124 | 126 | public void toStringTest() {
|
125 | 127 | JSONObject rawSchemaJson = ResourceLoader.DEFAULT.readObj("tostring/stringschema.json");
|
126 | 128 | String actual = SchemaLoader.load(rawSchemaJson).toString();
|
127 |
| - assertTrue(ObjectComparator.deepEquals(rawSchemaJson, new JSONObject(actual))); |
| 129 | + assertTrue(deepEquals(rawSchemaJson, new JSONObject(actual))); |
128 | 130 | }
|
129 | 131 |
|
130 | 132 | @Test
|
131 | 133 | public void toStringWithNullableTrueTest() {
|
132 | 134 | JSONObject rawSchemaJson = ResourceLoader.DEFAULT.readObj("tostring/stringschema.json");
|
133 | 135 | rawSchemaJson.put("nullable", true);
|
134 | 136 | String actual = loadWithNullableSupport(rawSchemaJson).toString();
|
135 |
| - assertTrue(ObjectComparator.deepEquals(rawSchemaJson, new JSONObject(actual))); |
| 137 | + assertTrue(deepEquals(rawSchemaJson, new JSONObject(actual))); |
136 | 138 | }
|
137 | 139 |
|
138 | 140 | @Test
|
139 | 141 | public void toStringWithNullableFalseTest() {
|
140 | 142 | JSONObject rawSchemaJson = ResourceLoader.DEFAULT.readObj("tostring/stringschema.json");
|
141 | 143 | rawSchemaJson.put("nullable", false);
|
142 | 144 | String actual = loadWithNullableSupport(rawSchemaJson).toString();
|
143 |
| - assertTrue(ObjectComparator.deepEquals(rawSchemaJson, new JSONObject(actual))); |
| 145 | + assertTrue(deepEquals(rawSchemaJson, new JSONObject(actual))); |
144 | 146 | }
|
145 | 147 |
|
146 | 148 | @Test
|
147 | 149 | public void toStringNoFormat() {
|
148 | 150 | JSONObject rawSchemaJson = ResourceLoader.DEFAULT.readObj("tostring/stringschema.json");
|
149 | 151 | rawSchemaJson.remove("format");
|
150 | 152 | String actual = SchemaLoader.load(rawSchemaJson).toString();
|
151 |
| - assertTrue(ObjectComparator.deepEquals(rawSchemaJson, new JSONObject(actual))); |
| 153 | + assertTrue(deepEquals(rawSchemaJson, new JSONObject(actual))); |
152 | 154 | }
|
153 | 155 |
|
154 | 156 | @Test
|
155 | 157 | public void toStringNoExplicitType() {
|
156 | 158 | JSONObject rawSchemaJson = ResourceLoader.DEFAULT.readObj("tostring/stringschema.json");
|
157 | 159 | rawSchemaJson.remove("type");
|
158 | 160 | String actual = SchemaLoader.load(rawSchemaJson).toString();
|
159 |
| - assertTrue(ObjectComparator.deepEquals(rawSchemaJson, new JSONObject(actual))); |
| 161 | + assertTrue(deepEquals(rawSchemaJson, new JSONObject(actual))); |
| 162 | + } |
| 163 | + |
| 164 | + @Test |
| 165 | + public void toString_ReadOnlyWriteOnly() { |
| 166 | + Schema subject = StringSchema.builder().readOnly(true).writeOnly(false).build(); |
| 167 | + JSONObject actual = new JSONObject(subject.toString()); |
| 168 | + |
| 169 | + JSONObject expected = ResourceLoader.DEFAULT.readObj("tostring/stringschema-readonly-true-writeonly-false.json"); |
| 170 | + assertTrue(deepEquals(actual, expected)); |
160 | 171 | }
|
161 | 172 |
|
162 | 173 | @Test
|
|
0 commit comments