Skip to content

Commit

Permalink
Add TYPE suffix to URI and URL factories to prevent shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio authored and joel-costigliola committed Jul 30, 2019
1 parent b770d0c commit 27f5560
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
18 changes: 14 additions & 4 deletions src/main/java/org/assertj/core/api/InstanceOfAssertFactories.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,25 @@ static <VALUE> InstanceOfAssertFactory<Optional, OptionalAssert<VALUE>> optional

/**
* {@link InstanceOfAssertFactory} for a {@link URI}.
* <p>
* Note: The {@code TYPE} suffix prevents the shadowing of {@code java.net.URI} when the factory is statically imported.
* </p>
*
* @since 3.13.2
*/
InstanceOfAssertFactory<URI, AbstractUriAssert<?>> URI = new InstanceOfAssertFactory<>(URI.class,
Assertions::assertThat);
InstanceOfAssertFactory<URI, AbstractUriAssert<?>> URI_TYPE = new InstanceOfAssertFactory<>(URI.class,
Assertions::assertThat);

/**
* {@link InstanceOfAssertFactory} for a {@link URL}.
* <p>
* Note: The {@code TYPE} suffix prevents the shadowing of {@code java.net.URL} when the factory is statically imported.
* </p>
*
* @since 3.13.2
*/
InstanceOfAssertFactory<URL, AbstractUrlAssert<?>> URL = new InstanceOfAssertFactory<>(URL.class,
Assertions::assertThat);
InstanceOfAssertFactory<URL, AbstractUrlAssert<?>> URL_TYPE = new InstanceOfAssertFactory<>(URL.class,
Assertions::assertThat);

/**
* {@link InstanceOfAssertFactory} for a {@code boolean} or its corresponding boxed type {@link Boolean}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
import static org.assertj.core.api.InstanceOfAssertFactories.STRING_BUFFER;
import static org.assertj.core.api.InstanceOfAssertFactories.STRING_BUILDER;
import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE;
import static org.assertj.core.api.InstanceOfAssertFactories.URI;
import static org.assertj.core.api.InstanceOfAssertFactories.URL;
import static org.assertj.core.api.InstanceOfAssertFactories.URI_TYPE;
import static org.assertj.core.api.InstanceOfAssertFactories.URL_TYPE;
import static org.assertj.core.api.InstanceOfAssertFactories.ZONED_DATE_TIME;
import static org.assertj.core.api.InstanceOfAssertFactories.array;
import static org.assertj.core.api.InstanceOfAssertFactories.atomicIntegerFieldUpdater;
Expand Down Expand Up @@ -113,6 +113,8 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.LocalDate;
Expand Down Expand Up @@ -319,21 +321,21 @@ void big_integer_factory_should_allow_big_integer_assertions() {
}

@Test
void uri_factory_should_allow_uri_assertions() {
void uri_type_factory_should_allow_uri_assertions() {
// GIVEN
Object value = java.net.URI.create("http://localhost");
Object value = URI.create("http://localhost");
// WHEN
AbstractUriAssert<?> result = assertThat(value).asInstanceOf(URI);
AbstractUriAssert<?> result = assertThat(value).asInstanceOf(URI_TYPE);
// THEN
result.hasHost("localhost");
}

@Test
void url_factory_should_allow_url_assertions() throws MalformedURLException {
void url_type_factory_should_allow_url_assertions() throws MalformedURLException {
// GIVEN
Object value = new java.net.URL("http://localhost");
Object value = new URL("http://localhost");
// WHEN
AbstractUrlAssert<?> result = assertThat(value).asInstanceOf(URL);
AbstractUrlAssert<?> result = assertThat(value).asInstanceOf(URL_TYPE);
// THEN
result.hasHost("localhost");
}
Expand Down

0 comments on commit 27f5560

Please sign in to comment.