|
| 1 | +package io.smallrye.common.resource; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 6 | +import static org.junit.jupiter.api.Assumptions.assumeTrue; |
| 7 | + |
| 8 | +import java.io.IOException; |
| 9 | +import java.io.InputStream; |
| 10 | +import java.net.URISyntaxException; |
| 11 | +import java.net.URL; |
| 12 | +import java.nio.file.Path; |
| 13 | + |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +public final class PathResourceLoaderTests { |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testLoading() throws IOException, URISyntaxException { |
| 20 | + URL myClass = PathResourceLoaderTests.class.getResource("PathResourceLoaderTests.class"); |
| 21 | + assumeTrue(myClass != null); |
| 22 | + assumeTrue("file".equals(myClass.getProtocol())); |
| 23 | + Path testClasses = Path.of(myClass.toURI()).getParent().getParent().getParent().getParent().getParent(); |
| 24 | + byte[] myClassBytes; |
| 25 | + try (InputStream is = myClass.openStream()) { |
| 26 | + assumeTrue(is != null); |
| 27 | + myClassBytes = is.readAllBytes(); |
| 28 | + } |
| 29 | + try (PathResourceLoader rl = new PathResourceLoader(testClasses)) { |
| 30 | + Resource myClassRsrc = rl.findResource("io/smallrye/common/resource/PathResourceLoaderTests.class"); |
| 31 | + assertNotNull(myClassRsrc); |
| 32 | + try (InputStream is = myClassRsrc.openStream()) { |
| 33 | + assertArrayEquals(myClassBytes, is.readAllBytes()); |
| 34 | + } |
| 35 | + URL url = myClassRsrc.url(); |
| 36 | + assertInstanceOf(ResourceURLConnection.class, url.openConnection()); |
| 37 | + } |
| 38 | + } |
| 39 | +} |
0 commit comments