Skip to content

Commit

Permalink
Merge pull request #1006 from andymc12/updateUriBuilderTest
Browse files Browse the repository at this point in the history
Update UriBuilderIT test
  • Loading branch information
andymc12 authored Aug 18, 2021
2 parents 0de8168 + 7cbb84c commit 82ed589
Showing 1 changed file with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.util.concurrent.TimeUnit.HOURS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.net.URI;
Expand Down Expand Up @@ -61,18 +62,55 @@ public final void shouldBuildValidInstanceFromScratch()
}

/**
* Verifies that no invalid URI can be created from scratch.
* Verifies that {@code UriBuilder#build()} creates an empty {@code URI}
* no other methods are called on it. The created {@code URI} should be
* equivalent to {@code URI.create("")}.
*
* @throws ExecutionException if the instance didn't boot correctly
* @throws InterruptedException if the test took much longer than usually
* expected
*/
@Test
public final void shouldNotBuildInvalidUriFromScratch() throws InterruptedException, ExecutionException {
public final void emptyUriBuilderBuildsEmptyUri() throws InterruptedException, ExecutionException {
// given
final UriBuilder uriBuilder = UriBuilder.newInstance();
final URI uri = UriBuilder.newInstance().build();
// then
assertEquals(URI.create(""), /* when */ uri);
}

/**
* Verifies that {@code UriBuilder#build()} throws a {@link UriBuilderException}
* when it would be asked to create an invalid URI.
*
* @throws ExecutionException if the instance didn't boot correctly
* @throws InterruptedException if the test took much longer than usually
* expected
*/
@Test
public final void shouldThrowUriBuilderExceptionOnSchemeOnlyUri() throws InterruptedException, ExecutionException {
// given
final UriBuilder uriBuilder = UriBuilder.newInstance().scheme("http");
// then
assertThrows(UriBuilderException.class, /* when */ uriBuilder::build);
}

/**
* Verifies that {@code UriBuilder#build()} throws a {@code IllegalArgumentException}
* when it would be asked to create a URI with unresolved template variables.
*
* @throws ExecutionException if the instance didn't boot correctly
* @throws InterruptedException if the test took much longer than usually
* expected
*/
@Test
public final void shouldThrowIllegalArgumentExceptionForUnresolvedTemplates() throws InterruptedException,
ExecutionException {
// given
final UriBuilder uriBuilder = UriBuilder.newInstance().scheme("http")
.host("localhost")
.path("contextroot")
.path("{var}");
// then
assertThrows(IllegalArgumentException.class, /* when */ uriBuilder::build);
}
}

0 comments on commit 82ed589

Please sign in to comment.