Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractUrlAssert<SELF extends AbstractUrlAssert<SELF>>

extends AbstractAssert<SELF extends AbstractUrlAssert<SELF>, URL>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.UrlAssert
Type Parameters
<SELF>
the "self" type of this assertion class.
Imports
java.net.URL, org.assertj.core.internal.Urls, org.assertj.core.util.VisibleForTesting

Base class for all implementations of assertions for URLs.
See Also
java.net.URL

Field Summary

Modifier and TypeField and Description
protected Urls
Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractUrlAssert(final URL actual, final Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
public SELF

Returns:

this assertion object.
hasAnchor
(String
the expected anchor of the actual URL.
expected
)

Verifies that the actual URL has the expected anchor.

public SELF

Returns:

this assertion object.
hasAuthority
(String
the expected authority of the actual URL.
expected
)

Verifies that the actual URL has the expected authority.

public SELF

Returns:

this assertion object.
hasHost
(String
the expected host of the actual URL.
expected
)

Verifies that the actual URL has the expected host.

public SELF

Returns:

this assertion object.
hasNoAnchor
()

Verifies that the actual URL has no anchor.

public SELF

Returns:

this assertion object.
hasNoHost
()

Verifies that the actual URL has no host.

public SELF

Returns:

this assertion object.
hasNoParameter
(String
the name of the parameter expected to be absent.
name
)

Verifies that the actual URL does not have a parameter with the specified name.

public SELF

Returns:

this assertion object.
hasNoParameter
(String
the name of the parameter expected to be absent.
name
,
String
the value of the parameter expected to be absent.
value
)

Verifies that the actual URL does not have a parameter with the expected name and value.

public SELF

Returns:

this assertion object.
hasNoParameters
()

Verifies that the actual URL does not have any parameters.

public SELF

Returns:

this assertion object.
hasNoPath
()

Verifies that the actual URL has no path.

public SELF

Returns:

this assertion object.
hasNoPort
()

Verifies that the actual URL has no port.

public SELF

Returns:

this assertion object.
hasNoQuery
()

Verifies that the actual URL has no query.

public SELF

Returns:

this assertion object.
hasNoUserInfo
()

Verifies that the actual URL has no userinfo.

public SELF

Returns:

this assertion object.
hasParameter
(String
the name of the parameter expected to be present.
name
)

Verifies that the actual URL has a parameter with the expected name.

public SELF

Returns:

this assertion object.
hasParameter
(String
the name of the parameter expected to be present.
name
,
String
the value of the parameter expected to be present.
value
)

Verifies that the actual URL has a parameter with the expected name and value.

public SELF

Returns:

this assertion object.
hasPath
(String
the expected path of the actual URL.
expected
)

Verifies that the actual URL has the expected path (which must not be null).

public SELF

Returns:

this assertion object.
hasPort
(int
the expected port of the actual URL.
expected
)

Verifies that the actual URL has the expected port.

public SELF

Returns:

this assertion object.
hasProtocol
(String
the expected protocol of the actual URL.
expected
)

Verifies that the actual URL has the expected protocol.

public SELF

Returns:

this assertion object.
hasQuery
(String
the expected query of the actual URL.
expected
)

Verifies that the actual URL has the expected query.

public SELF

Returns:

this assertion object.
hasUserInfo
(String
the expected userinfo of the actual URL.
expected
)

Verifies that the actual URL has the expected userinfo.

public SELF

Returns:

this assertion object.
isEqualToWithSortedQueryParameters
(URL
the expected URL to compare actual to.
expected
)

Verifies that the actual URL is equivalent to the given one after their parameters are sorted.

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingComparatorusingComparatorusingDefaultComparatorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError

Field Detail

urlsback to summary
protected Urls urls
Annotations
@VisibleForTesting

Constructor Detail

AbstractUrlAssertback to summary
protected AbstractUrlAssert(final URL actual, final Class<?> selfType)

Method Detail

hasAnchorback to summary
public SELF hasAnchor(String expected)

Verifies that the actual URL has the expected anchor.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/news.html#sport")).hasAnchor("sport");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/news.html#sport")).hasAnchor("war");
assertThat(new URL("http://www.helloworld.org/news.html")).hasAnchor("sport");
Parameters
expected:String

the expected anchor of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual anchor is not equal to the expected anchor.
hasAuthorityback to summary
public SELF hasAuthority(String expected)

Verifies that the actual URL has the expected authority.

Examples:

 // These assertions succeed:
assertThat(new URL("http://helloworld.org")).hasAuthority("helloworld.org");
assertThat(new URL("http://helloworld.org:8080")).hasAuthority("helloworld.org:8080");
assertThat(new URL("http://www.helloworld.org:8080/news")).hasAuthority("www.helloworld.org:8080");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org:8080")).hasAuthority("www.helloworld.org");
assertThat(new URL("http://www.helloworld.org")).hasAuthority("www.helloworld.org:8080");
Parameters
expected:String

the expected authority of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual authority is not equal to the expected authority.
hasHostback to summary
public SELF hasHost(String expected)

Verifies that the actual URL has the expected host.

Examples:

 // These assertions succeed:
assertThat(new URL("http://helloworld.org/pages")).hasHost("helloworld.org");
assertThat(new URL("http://helloworld.org:8080")).hasHost("helloworld.org");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org")).hasHost("helloworld.org");
assertThat(new URL("http://www.helloworld.org:8080")).hasHost("helloworld.org");
Parameters
expected:String

the expected host of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual host is not equal to the expected host.
hasNoAnchorback to summary
public SELF hasNoAnchor()

Verifies that the actual URL has no anchor.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/news.html")).hasNoAnchor();

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/news.html#sport")).hasNoAnchor();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has a anchor.
hasNoHostback to summary
public SELF hasNoHost()

Verifies that the actual URL has no host.

Examples:

 // This assertion succeeds:
assertThat(new URL("file:///home/user/Documents/hello-world.txt")).hasNoHost();

// This assertion fails:
assertThat(new URL("http://helloworld.org:8080/index.html")).hasNoHost();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has a host.
Since
3.22.0
hasNoParameterback to summary
public SELF hasNoParameter(String name)

Verifies that the actual URL does not have a parameter with the specified name.

The value of the parameter is not checked.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/index.html")).hasNoParameter("happy");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html?sad")).hasNoParameter("sad");
assertThat(new URL("http://www.helloworld.org/index.html?sad=much")).hasNoParameter("sad");
Parameters
name:String

the name of the parameter expected to be absent.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has the expected parameter.
IllegalArgumentException:
if the query string contains an invalid escape sequence.
Since
2.5.0 / 3.5.0
hasNoParameterback to summary
public SELF hasNoParameter(String name, String value)

Verifies that the actual URL does not have a parameter with the expected name and value.

Use null to indicate an absent value (e.g. foo&bar) as opposed to an empty value (e.g. foo=&bar=).

Examples:

 // These assertions succeed:
assertThat(new URL("http://www.helloworld.org/index.html")).hasNoParameter("happy", "very");
assertThat(new URL("http://www.helloworld.org/index.html?happy")).hasNoParameter("happy", "very");
assertThat(new URL("http://www.helloworld.org/index.html?happy=very")).hasNoParameter("happy", null);

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html?sad")).hasNoParameter("sad", null);
assertThat(new URL("http://www.helloworld.org/index.html?sad=much")).hasNoParameter("sad", "much");
Parameters
name:String

the name of the parameter expected to be absent.

value:String

the value of the parameter expected to be absent.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has the expected parameter.
IllegalArgumentException:
if the query string contains an invalid escape sequence.
Since
2.5.0 / 3.5.0
hasNoParametersback to summary
public SELF hasNoParameters()

Verifies that the actual URL does not have any parameters.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/index.html")).hasNoParameters();

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html?sad")).hasNoParameters();
assertThat(new URL("http://www.helloworld.org/index.html?sad=much")).hasNoParameters();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has a parameter.
IllegalArgumentException:
if the query string contains an invalid escape sequence.
Since
2.5.0 / 3.5.0
hasNoPathback to summary
public SELF hasNoPath()

Verifies that the actual URL has no path.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org")).hasNoPath();

// this assertion fails:
assertThat(new URL("http://helloworld.org/france")).hasNoPath();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has a path.
hasNoPortback to summary
public SELF hasNoPort()

Verifies that the actual URL has no port.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://helloworld.org")).hasNoPort();

// This assertion fails:
assertThat(new URL("http://helloworld.org:8080")).hasNoPort();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has a port.
hasNoQueryback to summary
public SELF hasNoQuery()

Verifies that the actual URL has no query.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/index.html")).hasNoQuery();

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html?type=test")).hasNoQuery();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has a query.
hasNoUserInfoback to summary
public SELF hasNoUserInfo()

Verifies that the actual URL has no userinfo.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/index.html")).hasNoUserInfo();

// This assertion fails:
assertThat(new URL("http://test:[email protected]/index.html")).hasNoUserInfo();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if actual has some userinfo.
hasParameterback to summary
public SELF hasParameter(String name)

Verifies that the actual URL has a parameter with the expected name.

The value of the parameter is not checked.

Examples:

 // These assertions succeed:
assertThat(new URL("http://www.helloworld.org/index.html?happy")).hasParameter("happy");
assertThat(new URL("http://www.helloworld.org/index.html?happy=very")).hasParameter("happy");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html")).hasParameter("happy");
assertThat(new URL("http://www.helloworld.org/index.html?sad=much")).hasParameter("happy");
Parameters
name:String

the name of the parameter expected to be present.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual does not have the expected parameter.
IllegalArgumentException:
if the query string contains an invalid escape sequence.
hasParameterback to summary
public SELF hasParameter(String name, String value)

Verifies that the actual URL has a parameter with the expected name and value.

Use null to indicate an absent value (e.g. foo&bar) as opposed to an empty value (e.g. foo=&bar=).

Examples:

 // These assertions succeed:
assertThat(new URL("http://www.helloworld.org/index.html?happy")).hasParameter("happy", null);
assertThat(new URL("http://www.helloworld.org/index.html?happy=very")).hasParameter("happy", "very");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html?sad")).hasParameter("sad", "much");
assertThat(new URL("http://www.helloworld.org/index.html?sad=much")).hasParameter("sad", null);
Parameters
name:String

the name of the parameter expected to be present.

value:String

the value of the parameter expected to be present.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual does not have the expected parameter.
IllegalArgumentException:
if the query string contains an invalid escape sequence.
hasPathback to summary
public SELF hasPath(String expected)

Verifies that the actual URL has the expected path (which must not be null).

Examples:

 // These assertions succeed:
assertThat(new URL("http://helloworld.org/pages")).hasPath("/pages");
assertThat(new URL("http://www.helloworld.org")).hasPath("");
// or preferably:
assertThat(new URL("http://www.helloworld.org")).hasNoPath();

// this assertion fails:
assertThat(new URL("http://helloworld.org/pickme")).hasPath("/pages/");

// this assertion throws an IllegalArgumentException:
assertThat(new URL("http://helloworld.org/pages")).hasPath(null);
Parameters
expected:String

the expected path of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual URL path is not equal to the expected path.
IllegalArgumentException:
if given path is null.
hasPortback to summary
public SELF hasPort(int expected)

Verifies that the actual URL has the expected port.

Examples:

 // These assertions succeed:
assertThat(new URL("http://helloworld.org:8080")).hasPort(8080);

// These assertions fail:
assertThat(new URL("http://helloworld.org:8080")).hasPort(9876);
assertThat(new URL("http://helloworld.org")).hasPort(8080);
Parameters
expected:int

the expected port of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual port is not equal to the expected port.
hasProtocolback to summary
public SELF hasProtocol(String expected)

Verifies that the actual URL has the expected protocol.

Examples:

 // This assertion succeeds:
assertThat(new URL("ftp://helloworld.org")).hasProtocol("ftp");

// This assertion fails:
assertThat(new URL("http://helloworld.org")).hasProtocol("ftp");
Parameters
expected:String

the expected protocol of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual protocol is not equal to the expected protocol.
hasQueryback to summary
public SELF hasQuery(String expected)

Verifies that the actual URL has the expected query.

Examples:

 // This assertion succeeds:
assertThat(new URL("http://www.helloworld.org/index.html?type=test")).hasQuery("type=test");

// These assertions fail:
assertThat(new URL("http://www.helloworld.org/index.html?type=test")).hasQuery("type=hello");
assertThat(new URL("http://www.helloworld.org/index.html")).hasQuery("type=hello");
Parameters
expected:String

the expected query of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual query is not equal to the expected query.
hasUserInfoback to summary
public SELF hasUserInfo(String expected)

Verifies that the actual URL has the expected userinfo.

Examples:

 // These assertions succeed:
assertThat(new URL("http://test:[email protected]/index.html")).hasUserInfo("test:pass");
assertThat(new URL("http://[email protected]/index.html")).hasUserInfo("test");
assertThat(new URL("http://:[email protected]/index.html")).hasUserInfo(":pass");

// These assertions fail:
assertThat(new URL("http://test:[email protected]/index.html")).hasUserInfo("test:fail");
assertThat(new URL("http://www.helloworld.org/index.html")).hasUserInfo("test:pass");
Parameters
expected:String

the expected userinfo of the actual URL.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual userinfo is not equal to the expected userinfo.
isEqualToWithSortedQueryParametersback to summary
public SELF isEqualToWithSortedQueryParameters(URL expected)

Verifies that the actual URL is equivalent to the given one after their parameters are sorted.

Example:

 URL url = new URL("http://example.com?a=b&c=d");

// this assertion succeeds ...
assertThat(url).isEqualToWithSortedQueryParameters(new URL("http://example.com?c=d&a=b"))
               .isEqualToWithSortedQueryParameters(new URL("http://example.com?a=b&c=d"));

// ... but this one fails as parameters do not match.
assertThat(url).isEqualToWithSortedQueryParameters(new URL("http://example.com?a=b&c=e"));

//... and this one fails as domains are different.
assertThat(url).isEqualToWithSortedQueryParameters(new URL("http://example2.com?amp;a=b&c=d")); 
Parameters
expected:URL

the expected URL to compare actual to.

Returns:SELF

this assertion object.

Exceptions
NullPointerException:
if the given URL is null.
AssertionError:
  • if the actual URL is null.
  • if the actual URL is not equivalent to the given one after their parameters are sorted.
Since
3.16.0