Skip to content

Commit

Permalink
Add test for path resource loader URL connection
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Oct 30, 2024
1 parent 4bbd830 commit d986e9d
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.smallrye.common.resource;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public final class PathResourceLoaderTests {

@Test
public void testLoading() throws IOException {
URL myClass = PathResourceLoaderTests.class.getResource("PathResourceLoaderTests.class");
assumeTrue(myClass != null);
assumeTrue("file".equals(myClass.getProtocol()));
String absPath = myClass.getPath();
Path testClasses = Path.of(absPath).getParent().getParent().getParent().getParent().getParent();
byte[] myClassBytes;
try (InputStream is = myClass.openStream()) {
assumeTrue(is != null);
myClassBytes = is.readAllBytes();
}
try (PathResourceLoader rl = new PathResourceLoader(testClasses)) {
Resource myClassRsrc = rl.findResource("io/smallrye/common/resource/PathResourceLoaderTests.class");
assertNotNull(myClassRsrc);
try (InputStream is = myClassRsrc.openStream()) {
assertArrayEquals(myClassBytes, is.readAllBytes());
}
URL url = myClassRsrc.url();
assertInstanceOf(ResourceURLConnection.class, url.openConnection());
}
}
}

0 comments on commit d986e9d

Please # to comment.