8
8
import static org .hamcrest .MatcherAssert .assertThat ;
9
9
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
10
import static org .junit .jupiter .api .Assertions .assertSame ;
11
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
11
12
import static org .junit .jupiter .api .Assertions .fail ;
12
13
import static org .mockito .Mockito .mock ;
13
14
import static org .mockito .Mockito .when ;
@@ -32,7 +33,7 @@ public class JsonPointerEvaluatorTest {
32
33
private static final ResourceLoader LOADER = ResourceLoader .DEFAULT ;
33
34
34
35
@ Test
35
- public void sameDocumentSuccess () {
36
+ void sameDocumentSuccess () {
36
37
JsonPointerEvaluator pointer = JsonPointerEvaluator .forDocument (rootSchemaJson , "#/definitions/Bar" );
37
38
JsonObject actual = pointer .query ().getQueryResult ().requireObject ();
38
39
assertEquals ("dummy schema at #/definitions/Bar" , actual .require ("description" ).requireString ());
@@ -41,7 +42,7 @@ public void sameDocumentSuccess() {
41
42
}
42
43
43
44
@ Test
44
- public void sameDocumentNotFound () {
45
+ void sameDocumentNotFound () {
45
46
Assertions .assertThrows (SchemaException .class , () -> {
46
47
JsonPointerEvaluator pointer = JsonPointerEvaluator .forDocument (rootSchemaJson , "#/definitions/NotFound" );
47
48
JsonObject actual = pointer .query ().getQueryResult ().requireObject ();
@@ -52,21 +53,21 @@ public void sameDocumentNotFound() {
52
53
}
53
54
54
55
@ Test
55
- public void arrayIndexSuccess () {
56
+ void arrayIndexSuccess () {
56
57
JsonPointerEvaluator pointer = JsonPointerEvaluator .forDocument (rootSchemaJson , "#/definitions/Array/0" );
57
58
JsonObject actual = pointer .query ().getQueryResult ().requireObject ();
58
59
assertEquals ("dummy schema in array" , actual .require ("description" ).requireString ());
59
60
}
60
61
61
62
@ Test
62
- public void rootRefSuccess () {
63
+ void rootRefSuccess () {
63
64
JsonPointerEvaluator pointer = JsonPointerEvaluator .forDocument (rootSchemaJson , "#" );
64
65
JsonObject actual = pointer .query ().getQueryResult ().requireObject ();
65
66
assertSame (rootSchemaJson , actual );
66
67
}
67
68
68
69
@ Test
69
- public void escaping () {
70
+ void escaping () {
70
71
JsonPointerEvaluator pointer = JsonPointerEvaluator .forDocument (rootSchemaJson , "#/definitions/Escaping/sla~1sh/ti~0lde" );
71
72
JsonObject actual = pointer .query ().getQueryResult ().requireObject ();
72
73
assertEquals ("tiled" , actual .require ("description" ).requireString ());
@@ -82,7 +83,7 @@ private LoadingState createLoadingState(SchemaClient schemaClient, String ref) {
82
83
}
83
84
84
85
@ Test
85
- public void remoteDocumentSuccess () throws URISyntaxException {
86
+ void remoteDocumentSuccess () throws URISyntaxException {
86
87
SchemaClient schemaClient = mock (SchemaClient .class );
87
88
when (schemaClient .get ("http://localhost:1234/hello" )).thenReturn (rootSchemaJsonAsStream ());
88
89
JsonPointerEvaluator pointer = JsonPointerEvaluator
@@ -94,9 +95,19 @@ public void remoteDocumentSuccess() throws URISyntaxException {
94
95
assertEquals (new SchemaLocation (new URI ("http://localhost:1234/hello" ), asList ("definitions" , "Bar" )),
95
96
actual .ls .pointerToCurrentObj );
96
97
}
98
+
99
+ @ Test
100
+ void remoteDocument_jsonParsingFailure () {
101
+ SchemaClient schemaClient = mock (SchemaClient .class );
102
+ when (schemaClient .get ("http://localhost:1234/hello" )).thenReturn (asStream ("unparseable" ));
103
+ SchemaException actual = assertThrows (SchemaException .class ,
104
+ () -> JsonPointerEvaluator .forURL (schemaClient , "http://localhost:1234/hello#/foo" , createLoadingState (schemaClient , "" )).query ()
105
+ );
106
+ assertEquals ("http://localhost:1234/hello" , actual .getSchemaLocation ());
107
+ }
97
108
98
109
@ Test
99
- public void schemaExceptionForInvalidURI () {
110
+ void schemaExceptionForInvalidURI () {
100
111
try {
101
112
SchemaClient schemaClient = mock (SchemaClient .class );
102
113
JsonPointerEvaluator subject = JsonPointerEvaluator .forURL (schemaClient , "||||" ,
0 commit comments