Skip to content

Commit b33aca8

Browse files
committed
minor code cleanup in CustomFormatValidatorTest
1 parent 9d4dfaf commit b33aca8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

core/src/test/java/org/everit/json/schema/loader/CustomFormatValidatorTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public String formatName() {
5151
@Test
5252
public void test() {
5353
SchemaLoader schemaLoader = SchemaLoader.builder()
54-
.schemaJson(loader.readObj("customformat-schema.json"))
54+
.schemaJson(baseSchemaJson())
5555
.addFormatValidator("evenlength", new EvenCharNumValidator())
5656
.build();
5757
try {
@@ -63,26 +63,33 @@ public void test() {
6363

6464
@Test
6565
public void nameOverride() {
66-
JSONObject rawSchemaJson = loader.readObj("customformat-schema.json");
66+
JSONObject rawSchemaJson = baseSchemaJson();
6767
JSONObject idPropSchema = (JSONObject) rawSchemaJson.query("/properties/id");
6868
idPropSchema.put("format", "somethingelse");
6969
SchemaLoader schemaLoader = SchemaLoader.builder()
7070
.schemaJson(rawSchemaJson)
7171
.addFormatValidator("somethingelse", new EvenCharNumValidator())
7272
.build();
73-
Object actual = new JSONObject(schemaLoader.load().build().toString())
74-
.query("/properties/id/format");
73+
Object actual = fetchFormatValueFromOutputJson(schemaLoader);
7574
assertEquals("somethingelse", actual);
7675
}
7776

77+
private Object fetchFormatValueFromOutputJson(SchemaLoader schemaLoader) {
78+
return new JSONObject(schemaLoader.load().build().toString())
79+
.query("/properties/id/format");
80+
}
81+
82+
private JSONObject baseSchemaJson() {
83+
return loader.readObj("customformat-schema.json");
84+
}
85+
7886
@Test
7987
public void formatValidatorWithoutExplicitName() {
8088
SchemaLoader schemaLoader = SchemaLoader.builder()
81-
.schemaJson(loader.readObj("customformat-schema.json"))
89+
.schemaJson(baseSchemaJson())
8290
.addFormatValidator(new EvenCharNumValidator())
8391
.build();
84-
Object actual = new JSONObject(schemaLoader.load().build().toString())
85-
.query("/properties/id/format");
92+
Object actual = fetchFormatValueFromOutputJson(schemaLoader);
8693
assertEquals("evenlength", actual);
8794
}
8895

0 commit comments

Comments
 (0)