Allow ClassPathResources to be filtered by FilteredClassLoader
See gh-14774
This commit is contained in:
committed by
Stephane Nicoll
parent
29c0aa4445
commit
d3ca1a7b0e
@@ -16,8 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.context;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@@ -25,9 +29,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* Tests for {@link FilteredClassLoader}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Roy Jacobs
|
||||
*/
|
||||
public class FilteredClassLoaderTests {
|
||||
|
||||
private static ClassPathResource TEST_RESOURCE = new ClassPathResource(
|
||||
"org/springframework/boot/test/context/FilteredClassLoaderTestResource.txt");
|
||||
|
||||
@Test
|
||||
public void loadClassWhenFilteredOnPackageShouldThrowClassNotFound()
|
||||
throws Exception {
|
||||
@@ -55,4 +63,22 @@ public class FilteredClassLoaderTests {
|
||||
classLoader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceWhenFilteredOnResourceShouldReturnNotFound()
|
||||
throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(TEST_RESOURCE)) {
|
||||
final URL loaded = classLoader.getResource(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
(resourceName) -> false)) {
|
||||
final URL loaded = classLoader.getResource(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Used by FilteredClassLoaderTests.java
|
||||
Reference in New Issue
Block a user