Skip to content

Commit

Permalink
Use URI#create (which does not throw a checked Exception) in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSchumacher committed Mar 12, 2019
1 parent 91af5c9 commit b600f5b
Show file tree
Hide file tree
Showing 29 changed files with 185 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;
import java.net.URISyntaxException;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -30,8 +29,8 @@ public class Assertions_assertThat_with_URI_Test {
private static URI uri;

@BeforeAll
public static void beforeClass() throws URISyntaxException {
uri = new URI("http://www.helloworld.org:8080/pages");
public static void beforeClass() {
uri = URI.create("http://www.helloworld.org:8080/pages");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -286,8 +285,8 @@ public void then_explicit_Object() {
}

@Test
public void then_URI() throws URISyntaxException {
then(new URI("http://assertj.org")).hasNoPort();
public void then_URI() {
then(URI.create("http://assertj.org")).hasNoPort();
}

}
5 changes: 2 additions & 3 deletions src/test/java/org/assertj/core/api/BDDSoftAssertionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.io.File;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -203,7 +202,7 @@ public void should_be_able_to_catch_exceptions_thrown_by_map_assertions() {

@SuppressWarnings("unchecked")
@Test
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() throws URISyntaxException {
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() {
// GIVEN
softly.then(BigDecimal.ZERO).isEqualTo(BigDecimal.ONE);
softly.then(Boolean.FALSE).isTrue();
Expand Down Expand Up @@ -278,7 +277,7 @@ public String toString() {
softly.then(OptionalInt.of(0)).isEqualTo(1);
softly.then(OptionalDouble.of(0.0)).isEqualTo(1.0);
softly.then(OptionalLong.of(0L)).isEqualTo(1L);
softly.then(new URI("http://assertj.org")).hasPort(8888);
softly.then(URI.create("http://assertj.org")).hasPort(8888);
softly.then(CompletableFuture.completedFuture("done")).hasFailed();
softly.then((Predicate<String>) s -> s.equals("something")).accepts("something else");
softly.then((IntPredicate) s -> s == 1).accepts(2);
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/assertj/core/api/SoftAssertionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.io.File;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -207,7 +206,7 @@ public void should_be_able_to_catch_exceptions_thrown_by_map_assertions() {

@SuppressWarnings("unchecked")
@Test
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() throws URISyntaxException {
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() {
try {
softly.assertThat(BigDecimal.ZERO).isEqualTo(BigDecimal.ONE);

Expand Down Expand Up @@ -309,7 +308,7 @@ public void call() throws Exception {
softly.assertThat(OptionalInt.of(0)).isEqualTo(1);
softly.assertThat(OptionalDouble.of(0.0)).isEqualTo(1.0);
softly.assertThat(OptionalLong.of(0L)).isEqualTo(1L);
softly.assertThat(new URI("http://assertj.org")).hasPort(8888);
softly.assertThat(URI.create("http://assertj.org")).hasPort(8888);
softly.assertThat(CompletableFuture.completedFuture("done")).hasFailed();
softly.assertThat((Predicate<String>) s -> s.equals("something")).accepts("something else");
softly.assertThat((IntPredicate) s -> s == 1).accepts(2);
Expand Down
7 changes: 1 addition & 6 deletions src/test/java/org/assertj/core/api/UriAssertBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.mockito.Mockito.mock;

import java.net.URI;
import java.net.URISyntaxException;

import org.assertj.core.internal.Uris;

Expand All @@ -28,11 +27,7 @@ public abstract class UriAssertBaseTest extends BaseTestTemplate<UriAssert, URI>

@Override
protected UriAssert create_assertions() {
try {
return new UriAssert(new URI("example.com/pages/"));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
return new UriAssert(URI.create("example.com/pages/"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.text.DateFormat;
Expand Down Expand Up @@ -800,7 +799,7 @@ public void withAssertions_assertThat_url_Test() throws MalformedURLException {
}

@Test
public void withAssertions_assertThat_uri_Test() throws URISyntaxException {
assertThat(new URI("https://github.com/joel-costigliola/assertj-core")).hasHost("github.com");
public void withAssertions_assertThat_uri_Test() {
assertThat(URI.create("https://github.com/joel-costigliola/assertj-core")).hasHost("github.com");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.assertj.core.api.BaseTest;
import org.assertj.core.data.Offset;
import org.assertj.core.error.OptionalDoubleShouldHaveValueCloseToOffset;
import org.junit.jupiter.api.Test;

public class OptionalDoubleAssert_hasValueCloseToOffset_Test extends BaseTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
public class ShouldHaveAuthority_create_Test {

@Test
public void should_create_error_message_for_uri() throws Exception {
URI uri = new URI("http://assertj.org:8080/news");
public void should_create_error_message_for_uri() {
URI uri = URI.create("http://assertj.org:8080/news");
String error = shouldHaveAuthority(uri, "foo.org").create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
public class ShouldHaveFragment_create_Test {

@Test
public void should_create_error_message_for_has_fragment() throws Exception {
URI uri = new URI("http://assertj.org/news#print");
public void should_create_error_message_for_has_fragment() {
URI uri = URI.create("http://assertj.org/news#print");
String error = shouldHaveFragment(uri, "foo").create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -38,8 +38,8 @@ public void should_create_error_message_for_has_fragment() throws Exception {
}

@Test
public void should_create_error_message_for_has_no_fragment() throws Exception {
URI uri = new URI("http://assertj.org/news#print");
public void should_create_error_message_for_has_no_fragment() {
URI uri = URI.create("http://assertj.org/news#print");
String error = shouldHaveFragment(uri, null).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
public class ShouldHaveHost_create_Test {

@Test
public void should_create_error_message_for_uri() throws Exception {
String error = shouldHaveHost(new URI("http://assertj.org/news"), "foo.org").create(new TestDescription("TEST"));
public void should_create_error_message_for_uri() {
String error = shouldHaveHost(URI.create("http://assertj.org/news"), "foo.org").create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
"Expecting host of%n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public class ShouldHaveParameter_create_Test {

@Test
public void should_create_error_message_for_missing_uri_parameter() throws Exception {
URI uri = new URI("http://assertj.org/news");
public void should_create_error_message_for_missing_uri_parameter() {
URI uri = URI.create("http://assertj.org/news");
String error = shouldHaveParameter(uri, "article").create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -40,8 +40,8 @@ public void should_create_error_message_for_missing_uri_parameter() throws Excep
}

@Test
public void should_create_error_message_for_uri_parameter_without_value_that_is_missing() throws Exception {
URI uri = new URI("http://assertj.org/news");
public void should_create_error_message_for_uri_parameter_without_value_that_is_missing() {
URI uri = URI.create("http://assertj.org/news");
String error = shouldHaveParameter(uri, "article", null).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -53,8 +53,8 @@ public void should_create_error_message_for_uri_parameter_without_value_that_is_
}

@Test
public void should_create_error_message_for_missing_uri_parameter_with_an_expected_value() throws Exception {
URI uri = new URI("http://assertj.org/news");
public void should_create_error_message_for_missing_uri_parameter_with_an_expected_value() {
URI uri = URI.create("http://assertj.org/news");
String error = shouldHaveParameter(uri, "article", "10").create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -68,8 +68,8 @@ public void should_create_error_message_for_missing_uri_parameter_with_an_expect
}

@Test
public void should_create_error_message_for_uri_parameter_without_value_that_has_one() throws Exception {
URI uri = new URI("http://assertj.org/news?article=10");
public void should_create_error_message_for_uri_parameter_without_value_that_has_one() {
URI uri = URI.create("http://assertj.org/news?article=10");
String error = shouldHaveParameter(uri, "article", null, newArrayList("10")).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -82,8 +82,8 @@ public void should_create_error_message_for_uri_parameter_without_value_that_has
}

@Test
public void should_create_error_message_for_uri_parameter_without_value_that_has_multiple_values() throws Exception {
URI uri = new URI("http://assertj.org/news?article=10");
public void should_create_error_message_for_uri_parameter_without_value_that_has_multiple_values() {
URI uri = URI.create("http://assertj.org/news?article=10");
String error = shouldHaveParameter(uri, "article", null,
newArrayList("10", "11")).create(new TestDescription("TEST"));

Expand All @@ -97,8 +97,8 @@ public void should_create_error_message_for_uri_parameter_without_value_that_has
}

@Test
public void should_create_error_message_for_uri_parameter_with_value_that_has_no_value() throws Exception {
URI uri = new URI("http://assertj.org/news?article");
public void should_create_error_message_for_uri_parameter_with_value_that_has_no_value() {
URI uri = URI.create("http://assertj.org/news?article");
String error = shouldHaveParameter(uri, "article", "10",
newArrayList((String) null)).create(new TestDescription("TEST"));

Expand All @@ -113,8 +113,8 @@ public void should_create_error_message_for_uri_parameter_with_value_that_has_no
}

@Test
public void should_create_error_message_for_uri_with_wrong_parameter_value() throws Exception {
URI uri = new URI("http://assertj.org/news?article=11");
public void should_create_error_message_for_uri_with_wrong_parameter_value() {
URI uri = URI.create("http://assertj.org/news?article=11");
String error = shouldHaveParameter(uri, "article", "10", newArrayList("11")).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -129,8 +129,8 @@ public void should_create_error_message_for_uri_with_wrong_parameter_value() thr
}

@Test
public void should_create_error_message_for_uri_with_wrong_parameter_values() throws Exception {
URI uri = new URI("http://assertj.org/news?article=11");
public void should_create_error_message_for_uri_with_wrong_parameter_values() {
URI uri = URI.create("http://assertj.org/news?article=11");
String error = shouldHaveParameter(uri, "article", "10",
newArrayList("11", "12")).create(new TestDescription("TEST"));

Expand All @@ -146,8 +146,8 @@ public void should_create_error_message_for_uri_with_wrong_parameter_values() th
}

@Test
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_even_without_value() throws Exception {
URI uri = new URI("http://assertj.org/news?article");
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_even_without_value() {
URI uri = URI.create("http://assertj.org/news?article");
String error = shouldHaveNoParameter(uri, "article", null).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -159,8 +159,8 @@ public void should_create_error_message_for_uri_with_no_parameter_that_has_one_e
}

@Test
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_with_value() throws Exception {
URI uri = new URI("http://assertj.org/news?article=10");
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_with_value() {
URI uri = URI.create("http://assertj.org/news?article=10");
String error = shouldHaveNoParameter(uri, "article", newArrayList("10")).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -173,8 +173,8 @@ public void should_create_error_message_for_uri_with_no_parameter_that_has_one_w
}

@Test
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_with_multiple_values() throws Exception {
URI uri = new URI("http://assertj.org/news?article=10");
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_with_multiple_values() {
URI uri = URI.create("http://assertj.org/news?article=10");
String error = shouldHaveNoParameter(uri, "article", newArrayList("10", "11")).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -187,8 +187,8 @@ public void should_create_error_message_for_uri_with_no_parameter_that_has_one_w
}

@Test
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_without_value() throws Exception {
URI uri = new URI("http://assertj.org/news?article");
public void should_create_error_message_for_uri_with_no_parameter_that_has_one_without_value() {
URI uri = URI.create("http://assertj.org/news?article");
String error = shouldHaveNoParameter(uri, "article", null, null).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand All @@ -200,8 +200,8 @@ public void should_create_error_message_for_uri_with_no_parameter_that_has_one_w
}

@Test
public void should_create_error_message_for_uri_no_parameter_value_but_found() throws Exception {
URI uri = new URI("http://assertj.org/news?article=10");
public void should_create_error_message_for_uri_no_parameter_value_but_found() {
URI uri = URI.create("http://assertj.org/news?article=10");
String error = shouldHaveNoParameter(uri, "article", "10", newArrayList("10")).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
public class ShouldHavePath_create_Test {

@Test
public void should_create_error_message_for_uri() throws Exception {
String error = shouldHavePath(new URI("http://assertj.org/news"), "/foo").create(new TestDescription("TEST"));
public void should_create_error_message_for_uri() {
String error = shouldHavePath(URI.create("http://assertj.org/news"), "/foo").create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
"Expecting path of%n" +
Expand All @@ -51,8 +51,8 @@ public void should_create_error_message_for_url() throws Exception {
}

@Test
public void should_create_error_message_for_uri_has_no_path() throws Exception {
URI uri = new URI("http://assertj.org/news?type=beta");
public void should_create_error_message_for_uri_has_no_path() {
URI uri = URI.create("http://assertj.org/news?type=beta");
String error = shouldHavePath(uri, null).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
public class ShouldHavePort_create_Test {

@Test
public void should_create_error_message_for_uri() throws Exception {
String error = shouldHavePort(new URI("http://assertj.org:8080/news"), 8888).create(new TestDescription("TEST"));
public void should_create_error_message_for_uri() {
String error = shouldHavePort(URI.create("http://assertj.org:8080/news"), 8888).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
"Expecting port of%n" +
Expand All @@ -38,8 +38,8 @@ public void should_create_error_message_for_uri() throws Exception {
}

@Test
public void should_create_error_message_for_uri_has_no_port() throws Exception {
URI uri = new URI("http://assertj.org:8080/news");
public void should_create_error_message_for_uri_has_no_port() {
URI uri = URI.create("http://assertj.org:8080/news");
String error = shouldHavePort(uri, -1).create(new TestDescription("TEST"));

assertThat(error).isEqualTo(format("[TEST] %n" +
Expand Down
Loading

0 comments on commit b600f5b

Please sign in to comment.