File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
main/java/org/springframework/aot/hint
test/java/org/springframework/aot/hint Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 27
27
import org .springframework .core .io .ClassPathResource ;
28
28
import org .springframework .core .io .Resource ;
29
29
import org .springframework .lang .Nullable ;
30
- import org .springframework .util .Assert ;
31
30
32
31
/**
33
32
* Gather the need for resources available at runtime.
@@ -115,19 +114,19 @@ public ResourceHints registerPattern(String include) {
115
114
116
115
/**
117
116
* Register that the supplied resource should be made available at runtime.
118
- * <p>If the supplied resource is not a {@link ClassPathResource}, it will
119
- * not be registered.
120
117
* @param resource the resource to register
121
- * @throws IllegalArgumentException if the supplied class path resource does
122
- * not {@linkplain Resource#exists() exist}
118
+ * @throws IllegalArgumentException if the supplied resource is not a
119
+ * {@link ClassPathResource} or does not {@linkplain Resource#exists() exist}
123
120
* @see #registerPattern(String)
124
121
* @see ClassPathResource#getAbsolutePath()
125
122
*/
126
123
public void registerResource (Resource resource ) {
127
- if (resource instanceof ClassPathResource classPathResource ) {
128
- Assert .isTrue (classPathResource .exists (), () -> "Resource does not exist: " + classPathResource );
124
+ if (resource instanceof ClassPathResource classPathResource && classPathResource .exists ()) {
129
125
registerPattern (classPathResource .getAbsolutePath ());
130
126
}
127
+ else {
128
+ throw new IllegalArgumentException ("Resource must be a ClassPathResource that exists: " + resource );
129
+ }
131
130
}
132
131
133
132
/**
Original file line number Diff line number Diff line change @@ -117,16 +117,17 @@ void registerIfPresentIgnoreMissingLocation() {
117
117
@ Test
118
118
void registerResourceWithUnsupportedResourceType () {
119
119
DescriptiveResource resource = new DescriptiveResource ("bogus" );
120
- this .resourceHints .registerResource (resource );
121
- assertThat (this .resourceHints .resourcePatterns ()).isEmpty ();
120
+ assertThatIllegalArgumentException ()
121
+ .isThrownBy (() -> this .resourceHints .registerResource (resource ))
122
+ .withMessage ("Resource must be a ClassPathResource that exists: %s" , resource );
122
123
}
123
124
124
125
@ Test
125
126
void registerResourceWithNonexistentClassPathResource () {
126
127
ClassPathResource resource = new ClassPathResource ("bogus" , getClass ());
127
128
assertThatIllegalArgumentException ()
128
129
.isThrownBy (() -> this .resourceHints .registerResource (resource ))
129
- .withMessage ("Resource does not exist : %s" , resource );
130
+ .withMessage ("Resource must be a ClassPathResource that exists : %s" , resource );
130
131
}
131
132
132
133
@ Test
You can’t perform that action at this time.
0 commit comments