Merge branch '2.1.x'
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.boot.test.context;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -81,4 +83,44 @@ public class FilteredClassLoaderTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourcesWhenFilteredOnResourceShouldReturnNotFound()
|
||||
throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(TEST_RESOURCE)) {
|
||||
final Enumeration<URL> loaded = classLoader
|
||||
.getResources(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded.hasMoreElements()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourcesWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
(resourceName) -> false)) {
|
||||
final Enumeration<URL> loaded = classLoader
|
||||
.getResources(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded.hasMoreElements()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceAsStreamWhenFilteredOnResourceShouldReturnNotFound()
|
||||
throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(TEST_RESOURCE)) {
|
||||
final InputStream loaded = classLoader
|
||||
.getResourceAsStream(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadResourceAsStreamWhenNotFilteredShouldLoadResource() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
(resourceName) -> false)) {
|
||||
final InputStream loaded = classLoader
|
||||
.getResourceAsStream(TEST_RESOURCE.getPath());
|
||||
assertThat(loaded).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user