Skip to content

Commit 6143362

Browse files
committed
refactor provider tests
1 parent 700e0b8 commit 6143362

13 files changed

+184
-153
lines changed

src/test/java/dev/harrel/jsonschema/Draft2019SpecificationTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
@SuppressWarnings("unused")
1212
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
13-
public abstract class Draft2019SpecificationTest {
13+
public abstract class Draft2019SpecificationTest implements ProviderTest {
1414
private static final Logger logger = Logger.getLogger("SpecificationTest");
1515
private Validator validator;
1616

17-
abstract protected JsonNodeFactory getJsonNodeFactory();
18-
1917
@BeforeAll
2018
void beforeAll() {
2119
validator = new ValidatorFactory()

src/test/java/dev/harrel/jsonschema/Draft2020EvaluatorFactoryTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import static java.util.Collections.emptyMap;
1515
import static org.assertj.core.api.Assertions.assertThat;
1616

17-
public abstract class Draft2020EvaluatorFactoryTest {
18-
19-
protected static JsonNodeFactory nodeFactory;
17+
public abstract class Draft2020EvaluatorFactoryTest implements ProviderTest {
2018
private static final Map<SimpleType, String> TYPE_MAP = Map.of(
2119
NULL, "null",
2220
BOOLEAN, "true",
@@ -35,7 +33,7 @@ void shouldCreateEvaluatorOnlyForSupportedTypes(String keyword, Set<SimpleType>
3533
SchemaParsingContext ctx = new SchemaParsingContext(dialect, new SchemaRegistry(), URI.create("CoreEvaluatorFactoryTest"), emptyMap());
3634

3735
for (var entry : TYPE_MAP.entrySet()) {
38-
JsonNode wrappedNode = nodeFactory.create("{\"%s\": %s}".formatted(keyword, entry.getValue()));
36+
JsonNode wrappedNode = getJsonNodeFactory().create("{\"%s\": %s}".formatted(keyword, entry.getValue()));
3937
Optional<Evaluator> evaluator = evaluatorFactory.create(ctx, keyword, wrappedNode.asObject().get(keyword));
4038
if (supportedTypes.contains(entry.getKey())) {
4139
assertThat(evaluator)

src/test/java/dev/harrel/jsonschema/Draft2020SpecificationTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
@SuppressWarnings("unused")
1212
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
13-
public abstract class Draft2020SpecificationTest {
13+
public abstract class Draft2020SpecificationTest implements ProviderTest {
1414
private static final Logger logger = Logger.getLogger("SpecificationTest");
1515
private Validator validator;
1616

17-
abstract protected JsonNodeFactory getJsonNodeFactory();
18-
1917
@BeforeAll
2018
void beforeAll() {
2119
validator = new ValidatorFactory()

src/test/java/dev/harrel/jsonschema/JsonNodeTest.java

+29-17
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010

1111
import static org.assertj.core.api.Assertions.assertThat;
1212

13-
public abstract class JsonNodeTest {
14-
15-
protected static JsonNodeFactory nodeFactory;
13+
public abstract class JsonNodeTest implements ProviderTest {
1614

1715
@Test
1816
void nullNode() {
19-
JsonNode node = nodeFactory.create("null");
17+
JsonNode node = getJsonNodeFactory().create("null");
2018
assertThat(node).isNotNull();
2119
assertThat(node.getNodeType()).isEqualTo(SimpleType.NULL);
2220
assertThat(node.isNull()).isTrue();
@@ -31,7 +29,7 @@ void nullNode() {
3129

3230
@Test
3331
void booleanNode() {
34-
JsonNode node = nodeFactory.create("true");
32+
JsonNode node = getJsonNodeFactory().create("true");
3533
assertThat(node).isNotNull();
3634
assertThat(node.getNodeType()).isEqualTo(SimpleType.BOOLEAN);
3735
assertThat(node.isNull()).isFalse();
@@ -48,7 +46,7 @@ void booleanNode() {
4846
@Test
4947
void stringNode() {
5048
String value = "~!@#$%6 anything \uD83D\uDCA9";
51-
JsonNode node = nodeFactory.create("\"" + value + "\"");
49+
JsonNode node = getJsonNodeFactory().create("\"" + value + "\"");
5250
assertThat(node).isNotNull();
5351
assertThat(node.getNodeType()).isEqualTo(SimpleType.STRING);
5452
assertThat(node.isNull()).isFalse();
@@ -76,7 +74,7 @@ void stringNode() {
7674
"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
7775
})
7876
void integerNode(String value) {
79-
JsonNode node = nodeFactory.create(value);
77+
JsonNode node = getJsonNodeFactory().create(value);
8078
assertThat(node).isNotNull();
8179
assertThat(node.getNodeType()).isEqualTo(SimpleType.INTEGER);
8280
assertThat(node.isNull()).isFalse();
@@ -114,7 +112,7 @@ void integerNode(String value) {
114112
"0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
115113
})
116114
void numberNode(String value) {
117-
JsonNode node = nodeFactory.create(value);
115+
JsonNode node = getJsonNodeFactory().create(value);
118116
assertThat(node).isNotNull();
119117
assertThat(node.getNodeType()).isEqualTo(SimpleType.NUMBER);
120118
assertThat(node.isNull()).isFalse();
@@ -138,7 +136,7 @@ void numberNode(String value) {
138136
@Test
139137
void arrayNode() {
140138
String value = "[null, true, \"a\", 1, 1.2]";
141-
JsonNode node = nodeFactory.create(value);
139+
JsonNode node = getJsonNodeFactory().create(value);
142140
assertThat(node).isNotNull();
143141
assertThat(node.getNodeType()).isEqualTo(SimpleType.ARRAY);
144142
assertThat(node.isNull()).isFalse();
@@ -155,7 +153,7 @@ void arrayNode() {
155153
@Test
156154
void objectNode() {
157155
String value = "{\"a\": null, \"b\": 1, \"c\": {}}";
158-
JsonNode node = nodeFactory.create(value);
156+
JsonNode node = getJsonNodeFactory().create(value);
159157
assertThat(node).isNotNull();
160158
assertThat(node.getNodeType()).isEqualTo(SimpleType.OBJECT);
161159
assertThat(node.isNull()).isFalse();
@@ -171,37 +169,37 @@ void objectNode() {
171169

172170
@Test
173171
void jsonPointerForNull() {
174-
JsonNode node = nodeFactory.create("null");
172+
JsonNode node = getJsonNodeFactory().create("null");
175173
assertThat(node.getJsonPointer()).isEmpty();
176174
}
177175

178176
@Test
179177
void jsonPointerForBoolean() {
180-
JsonNode node = nodeFactory.create("false");
178+
JsonNode node = getJsonNodeFactory().create("false");
181179
assertThat(node.getJsonPointer()).isEmpty();
182180
}
183181

184182
@Test
185183
void jsonPointerForString() {
186-
JsonNode node = nodeFactory.create("\"anything\"");
184+
JsonNode node = getJsonNodeFactory().create("\"anything\"");
187185
assertThat(node.getJsonPointer()).isEmpty();
188186
}
189187

190188
@Test
191189
void jsonPointerForInteger() {
192-
JsonNode node = nodeFactory.create("123");
190+
JsonNode node = getJsonNodeFactory().create("123");
193191
assertThat(node.getJsonPointer()).isEmpty();
194192
}
195193

196194
@Test
197195
void jsonPointerForNumber() {
198-
JsonNode node = nodeFactory.create("123.321");
196+
JsonNode node = getJsonNodeFactory().create("123.321");
199197
assertThat(node.getJsonPointer()).isEmpty();
200198
}
201199

202200
@Test
203201
void jsonPointerForArray() {
204-
JsonNode node = nodeFactory.create("[[1, 2], []]");
202+
JsonNode node = getJsonNodeFactory().create("[[1, 2], []]");
205203
assertThat(node.getJsonPointer()).isEmpty();
206204
List<JsonNode> nodes = node.asArray();
207205
assertThat(nodes.get(0).getJsonPointer()).isEqualTo("/0");
@@ -212,7 +210,7 @@ void jsonPointerForArray() {
212210

213211
@Test
214212
void jsonPointerForObject() {
215-
JsonNode node = nodeFactory.create("{\"a\": [1, {\"b\": 2}]}");
213+
JsonNode node = getJsonNodeFactory().create("{\"a\": [1, {\"b\": 2}]}");
216214
assertThat(node.getJsonPointer()).isEmpty();
217215
Map<String, JsonNode> object = node.asObject();
218216
assertThat(object.get("a").getJsonPointer()).isEqualTo("/a");
@@ -223,6 +221,8 @@ void jsonPointerForObject() {
223221

224222
@Test
225223
void nullEquals() {
224+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
225+
226226
JsonNode node1 = nodeFactory.create("null");
227227
JsonNode node2 = nodeFactory.create("null");
228228
assertThat(node1.isEqualTo(node2)).isTrue();
@@ -238,6 +238,8 @@ void nullEquals() {
238238

239239
@Test
240240
void booleanEquals() {
241+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
242+
241243
JsonNode node1 = nodeFactory.create("true");
242244
JsonNode node2 = nodeFactory.create("true");
243245
assertThat(node1.isEqualTo(node2)).isTrue();
@@ -254,6 +256,8 @@ void booleanEquals() {
254256

255257
@Test
256258
void stringEquals() {
259+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
260+
257261
JsonNode node1 = nodeFactory.create("\"a\"");
258262
JsonNode node2 = nodeFactory.create("\"a\"");
259263
assertThat(node1.isEqualTo(node2)).isTrue();
@@ -270,6 +274,8 @@ void stringEquals() {
270274

271275
@Test
272276
void integerEquals() {
277+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
278+
273279
JsonNode node1 = nodeFactory.create("123");
274280
JsonNode node2 = nodeFactory.create("123");
275281
assertThat(node1.isEqualTo(node2)).isTrue();
@@ -287,6 +293,8 @@ void integerEquals() {
287293

288294
@Test
289295
void numberEquals() {
296+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
297+
290298
JsonNode node1 = nodeFactory.create("1.01");
291299
JsonNode node2 = nodeFactory.create("1.01");
292300
assertThat(node1.isEqualTo(node2)).isTrue();
@@ -303,6 +311,8 @@ void numberEquals() {
303311

304312
@Test
305313
void arrayEquals() {
314+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
315+
306316
String value = "[null, true, \"a\", 1, 1.2]";
307317
JsonNode node1 = nodeFactory.create(value);
308318
JsonNode node2 = nodeFactory.create(value);
@@ -323,6 +333,8 @@ void arrayEquals() {
323333

324334
@Test
325335
void objectEquals() {
336+
JsonNodeFactory nodeFactory = getJsonNodeFactory();
337+
326338
String value = "{\"a\": [1, {\"b\": 2}], \"b\": 1}";
327339
JsonNode node1 = nodeFactory.create(value);
328340
JsonNode node2 = nodeFactory.create(value);

0 commit comments

Comments
 (0)