Package org.assertj.core.api
Class AbstractUrlAssert<SELF extends AbstractUrlAssert<SELF>>
java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,URL>
org.assertj.core.api.AbstractUrlAssert<SELF>
- Type Parameters:
SELF
- the "self" type of this assertion class.
- All Implemented Interfaces:
Assert<SELF,
,URL> Descriptable<SELF>
,ExtensionPoints<SELF,
URL>
- Direct Known Subclasses:
UrlAssert
public abstract class AbstractUrlAssert<SELF extends AbstractUrlAssert<SELF>>
extends AbstractAssert<SELF,URL>
Base class for all implementations of assertions for
URL
s.- See Also:
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionVerifies that the actualURL
has the expected anchor.hasAuthority
(String expected) Verifies that the actualURL
has the expected authority.Verifies that the actualURL
has the expected host.Verifies that the actualURL
has no anchor.Verifies that the actualURL
has no host.hasNoParameter
(String name) Verifies that the actualURL
does not have a parameter with the specified name.hasNoParameter
(String name, String value) Verifies that the actualURL
does not have a parameter with the expected name and value.Verifies that the actualURL
does not have any parameters.Verifies that the actualURL
has no path.Verifies that the actualURL
has no port.Verifies that the actualURL
has no query.Verifies that the actualURL
has no userinfo.hasParameter
(String name) Verifies that the actualURL
has a parameter with the expected name.hasParameter
(String name, String value) Verifies that the actualURL
has a parameter with the expected name and value.Verifies that the actualURL
has the expected path (which must not be null).hasPort
(int expected) Verifies that the actualURL
has the expected port.hasProtocol
(String expected) Verifies that the actualURL
has the expected protocol.Verifies that the actualURL
has the expected query.hasUserInfo
(String expected) Verifies that the actualURL
has the expected userinfo.isEqualToWithSortedQueryParameters
(URL expected) Verifies that the actualURL
is equivalent to the given one after their parameters are sorted.Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs
-
Field Details
-
urls
protected org.assertj.core.internal.Urls urls
-
-
Constructor Details
-
AbstractUrlAssert
-
-
Method Details
-
hasProtocol
Verifies that the actualURL
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
- the expected protocol of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual protocol is not equal to the expected protocol.
-
hasPath
Verifies that the actualURL
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
- the expected path of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual URL path is not equal to the expected path.IllegalArgumentException
- if given path is null.
-
hasNoPath
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if the actual has a path.
-
hasPort
Verifies that the actualURL
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
- the expected port of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual port is not equal to the expected port.
-
hasNoPort
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if the actual has a port.
-
hasHost
Verifies that the actualURL
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
- the expected host of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual host is not equal to the expected host.
-
hasNoHost
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if actual has a host.- Since:
- 3.22.0
-
hasAuthority
Verifies that the actualURL
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
- the expected authority of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual authority is not equal to the expected authority.
-
hasQuery
Verifies that the actualURL
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
- the expected query of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual query is not equal to the expected query.
-
hasNoQuery
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if the actual has a query.
-
hasAnchor
Verifies that the actualURL
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
- the expected anchor of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual anchor is not equal to the expected anchor.
-
hasNoAnchor
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if the actual has a anchor.
-
hasUserInfo
Verifies that the actualURL
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
- the expected userinfo of the actualURL
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual userinfo is not equal to the expected userinfo.
-
hasNoUserInfo
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if the actual has some userinfo.
-
hasParameter
Verifies that the actualURL
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
- the name of the parameter expected to be present.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual does not have the expected parameter.IllegalArgumentException
- if the query string contains an invalid escape sequence.
-
hasParameter
Verifies that the actualURL
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
- the name of the parameter expected to be present.value
- the value of the parameter expected to be present.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual does not have the expected parameter.IllegalArgumentException
- if the query string contains an invalid escape sequence.
-
hasNoParameters
Verifies that the actualURL
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:
this
assertion object.- Throws:
AssertionError
- if the actual has a parameter.IllegalArgumentException
- if the query string contains an invalid escape sequence.- Since:
- 2.5.0 / 3.5.0
-
hasNoParameter
Verifies that the actualURL
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
- the name of the parameter expected to be absent.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual has the expected parameter.IllegalArgumentException
- if the query string contains an invalid escape sequence.- Since:
- 2.5.0 / 3.5.0
-
hasNoParameter
Verifies that the actualURL
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
- the name of the parameter expected to be absent.value
- the value of the parameter expected to be absent.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual has the expected parameter.IllegalArgumentException
- if the query string contains an invalid escape sequence.- Since:
- 2.5.0 / 3.5.0
-
isEqualToWithSortedQueryParameters
Verifies that the actualURL
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
- the expectedURL
to compare actual to.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given URL isnull
.AssertionError
- if the actualURL
isnull
.AssertionError
- if the actualURL
is not equivalent to the given one after their parameters are sorted.- Since:
- 3.16.0
-