Skip to content

Commit 9bacceb

Browse files
authored
Merge pull request #135 from erosb/const-schema-tostring
adding missing ConstSchema#decribePropertiesTo() method
2 parents 5bf8380 + cc8150e commit 9bacceb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

core/src/main/java/org/everit/json/schema/ConstSchema.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static org.everit.json.schema.EnumSchema.toJavaValue;
44

5+
import org.everit.json.schema.internal.JSONPrinter;
6+
57
public class ConstSchema extends Schema {
68

79
public static class ConstSchemaBuilder extends Schema.Builder<ConstSchema> {
@@ -29,6 +31,11 @@ protected ConstSchema(ConstSchemaBuilder builder) {
2931
this.permittedValue = toJavaValue(builder.permittedValue);
3032
}
3133

34+
@Override void describePropertiesTo(JSONPrinter writer) {
35+
writer.key("const");
36+
writer.value(this.permittedValue);
37+
}
38+
3239
@Override void accept(Visitor visitor) {
3340
visitor.visitConstSchema(this);
3441
}

core/src/test/java/org/everit/json/schema/ConstSchemaTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.everit.json.schema;
22

33
import static org.everit.json.schema.TestSupport.loadAsV6;
4+
import static org.junit.Assert.assertEquals;
45

56
import org.json.JSONArray;
67
import org.json.JSONObject;
@@ -56,6 +57,27 @@ public void successWithObject() {
5657
testSuccess(new JSONObject("{\"a\":\"b\", \"b\":\"a\"}"));
5758
}
5859

60+
@Test
61+
public void toStringTest() {
62+
ConstSchema subject = ConstSchema.builder().permittedValue(true).build();
63+
String actual = subject.toString();
64+
assertEquals("{\"const\":true}", actual);
65+
}
66+
67+
@Test
68+
public void toStringWithNull() {
69+
ConstSchema subject = ConstSchema.builder().permittedValue(null).build();
70+
String actual = subject.toString();
71+
assertEquals("{\"const\":null}", actual);
72+
}
73+
74+
@Test
75+
public void toStringWithObject() {
76+
ConstSchema subject = ConstSchema.builder().permittedValue(new JSONObject("{\"a\":2}")).build();
77+
String actual = subject.toString();
78+
assertEquals("{\"const\":{\"a\":2}}", actual);
79+
}
80+
5981
@Test
6082
public void failureWithObject() {
6183
testFailure(new JSONObject("{}"), new JSONObject("{\"a\":null}"));

0 commit comments

Comments
 (0)