Skip to content

Commit 9d3af08

Browse files
committed
Add test for path resource loader URL connection
1 parent 4bbd830 commit 9d3af08

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)