Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Nov 20, 2017
1 parent 736953d commit 2d119e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public URL resolve(
final Optional<String> fileBaseLocation) {

try {
final URI schemaUri = URI.create(fileBaseLocation.orElse(AN_EMPTY_STRING)).resolve(fileLocation);
final URI schemaUri = new URI(fileBaseLocation.orElse(AN_EMPTY_STRING)).resolve(fileLocation);
final URI resolvedUri = uriResolver.resolve(catalogUri, schemaUri);

return urlConverter.toUrl(resolvedUri);

} catch (final IllegalArgumentException | URISyntaxException e) {
throw new SchemaCatalogException(format("Failed to resolve %s, %s, %s", catalogUri, fileLocation, fileBaseLocation.orElse(null)), e);
} catch (final URISyntaxException e) {
throw new SchemaCatalogException(format("Failed to resolve '%s', to file location '%s', with base location '%s'", catalogUri, fileLocation, fileBaseLocation.orElse(null)), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import uk.gov.justice.schema.catalog.util.UriResolver;
import uk.gov.justice.schema.catalog.util.UrlConverter;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Optional;

Expand Down Expand Up @@ -57,4 +60,21 @@ public void shouldResolveTheLocationToAUrlUsingTheCatalogUrlAndAnEmptyBaseLocati

assertThat(resolvedUri.toString(), is("file:/src/main/some/path/to.json"));
}

@Test
public void shouldFailIfResolvingTheUrlThrowsAURISyntaxException() throws Exception {

final URI catalogUri = new URI("file:/src/main/schema.json");

final String fileLocation = "some/path/to.json";
final Optional<String> baseLocation = of("this path is silly");

try {
schemaResolver.resolve(catalogUri, fileLocation, baseLocation);
fail();
} catch (final SchemaCatalogException expected) {
assertThat(expected.getCause(), is(instanceOf(URISyntaxException.class)));
assertThat(expected.getMessage(), is("Failed to resolve 'file:/src/main/schema.json', to file location 'some/path/to.json', with base location 'this path is silly'"));
}
}
}

0 comments on commit 2d119e6

Please sign in to comment.