File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
main/java/org/everit/json/schema
test/java/org/everit/json/schema Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import static org .everit .json .schema .EnumSchema .toJavaValue ;
4
4
5
+ import org .everit .json .schema .internal .JSONPrinter ;
6
+
5
7
public class ConstSchema extends Schema {
6
8
7
9
public static class ConstSchemaBuilder extends Schema .Builder <ConstSchema > {
@@ -29,6 +31,11 @@ protected ConstSchema(ConstSchemaBuilder builder) {
29
31
this .permittedValue = toJavaValue (builder .permittedValue );
30
32
}
31
33
34
+ @ Override void describePropertiesTo (JSONPrinter writer ) {
35
+ writer .key ("const" );
36
+ writer .value (this .permittedValue );
37
+ }
38
+
32
39
@ Override void accept (Visitor visitor ) {
33
40
visitor .visitConstSchema (this );
34
41
}
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
3
3
import static org .everit .json .schema .TestSupport .loadAsV6 ;
4
+ import static org .junit .Assert .assertEquals ;
4
5
5
6
import org .json .JSONArray ;
6
7
import org .json .JSONObject ;
@@ -56,6 +57,27 @@ public void successWithObject() {
56
57
testSuccess (new JSONObject ("{\" a\" :\" b\" , \" b\" :\" a\" }" ));
57
58
}
58
59
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
+
59
81
@ Test
60
82
public void failureWithObject () {
61
83
testFailure (new JSONObject ("{}" ), new JSONObject ("{\" a\" :null}" ));
You can’t perform that action at this time.
0 commit comments