Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (core): ResourceProviders never returns null #886

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions java/dev/enola/common/io/resource/ResourceProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import dev.enola.common.io.iri.URIs;

import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -71,17 +70,16 @@ public ResourceProviders() {
}

@Override
public @Nullable Resource getResource(final URI uri) {
public Resource getResource(final URI uri) {
var resolvedURI = URIs.absolutify(uri);

for (ResourceProvider resourceProvider : resourceProviders) {
var resource = resourceProvider.getResource(resolvedURI);
if (resource != null) return resource;
}

// TODO warn instead of debug - or does that create a shitload of logging?
LOG.debug("Unsupported URI: {}", resolvedURI);
return null;
throw new IllegalArgumentException(
"Unsupported scheme, but try activating one of the --XYZ-scheme flags: " + uri);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void testNoScheme() {
() -> new ResourceProviders().getResource(URI.create("test:something")));
}

@Test
@Test(expected = IllegalArgumentException.class)
public void testUnknownScheme() {
assertThat(new ResourceProviders().getResource(URI.create("xyz-unknown:test"))).isNull();
}
Expand Down
6 changes: 3 additions & 3 deletions java/dev/enola/rdf/io/RdfResourceIntoThingConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RdfResourceIntoThingConverterTest {

DatatypeRepository datatypeRepository = new DatatypeRepositoryBuilder().build();
ResourceProvider resourceProvider =
new ResourceProviders(new ClasspathResource.Provider(), new FileResource.Provider());
new ResourceProviders(new ClasspathResource.Provider(), new EmptyResource.Provider());
RdfResourceIntoThingConverter c =
new RdfResourceIntoThingConverter<Thing>(resourceProvider, datatypeRepository);

Expand All @@ -50,8 +50,8 @@ public void emptyYAML() throws IOException {
}

@Test
public void directory() throws IOException {
assertThat(convert(URI.create("file:/tmp/"))).isEmpty();
public void empty() throws IOException {
assertThat(convert(EmptyResource.EMPTY_URI)).isEmpty();
}

private Iterable<Thing.Builder<?>> convert(URI uri) throws IOException {
Expand Down