File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
main/java/org/everit/json/schema/loader
test/java/org/everit/json/schema/loader Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 4
4
import static java .util .Collections .unmodifiableList ;
5
5
import static java .util .Objects .requireNonNull ;
6
6
7
+ import java .io .IOException ;
7
8
import java .io .InputStream ;
9
+ import java .io .UncheckedIOException ;
8
10
import java .util .List ;
9
11
import java .util .Optional ;
10
12
@@ -19,9 +21,17 @@ class ClassPathAwareSchemaClient implements SchemaClient {
19
21
}
20
22
21
23
@ Override public InputStream get (String url ) {
22
- return handleProtocol (url )
23
- .map (this ::loadFromClasspath )
24
- .orElseGet (() -> fallbackClient .get (url ));
24
+ Optional <String > maybeString = handleProtocol (url );
25
+ if (maybeString .isPresent ()) {
26
+ InputStream stream = this .loadFromClasspath (maybeString .get ());
27
+ if (stream != null ) {
28
+ return stream ;
29
+ } else {
30
+ throw new UncheckedIOException (new IOException (String .format ("Could not find %s" , url )));
31
+ }
32
+ } else {
33
+ return fallbackClient .get (url );
34
+ }
25
35
}
26
36
27
37
private InputStream loadFromClasspath (String str ) {
Original file line number Diff line number Diff line change 7
7
import static org .mockito .Mockito .when ;
8
8
9
9
import java .io .InputStream ;
10
+ import java .io .UncheckedIOException ;
10
11
11
12
import org .everit .json .schema .ResourceLoader ;
12
13
import org .json .JSONObject ;
13
14
import org .json .JSONTokener ;
14
15
import org .junit .Before ;
16
+ import org .junit .Rule ;
15
17
import org .junit .Test ;
18
+ import org .junit .rules .ExpectedException ;
16
19
import org .junit .runner .RunWith ;
17
20
18
21
import junitparams .JUnitParamsRunner ;
@@ -39,6 +42,18 @@ public void delegatesUnhandledProtocolsToFallback() {
39
42
assertSame (expected , actual );
40
43
}
41
44
45
+ @ Rule
46
+ public ExpectedException exception = ExpectedException .none ();
47
+ @ Test
48
+ public void throwsErrorOnMissingClasspathResource () {
49
+ exception .expect (UncheckedIOException .class );
50
+ exception .expectMessage ("Could not find" );
51
+
52
+ String url = "classpath:/bogus.json" ;
53
+ ClassPathAwareSchemaClient subject = new ClassPathAwareSchemaClient (fallbackClient );
54
+ subject .get (url );
55
+ }
56
+
42
57
@ Test
43
58
@ Parameters ({
44
59
"classpath:/org/everit/jsonvalidator/constobject.json" ,
You can’t perform that action at this time.
0 commit comments