public final class UrlCheck extends ObjectBaseCheck<URL,UrlCheck>
URL
arguments.
It provides a quick method to assert a certain protocol (
hasProtocol(String)
) and other than that provides property checks
for all properties, including host, file, port, query, etc.
arg, nullAllowed
Constructor and Description |
---|
UrlCheck(URL arg)
For internal use only.
|
Modifier and Type | Method and Description |
---|---|
StringCheck |
hasAuthorityWhich()
Creates an
StringCheck property check for the authority of the
URL argument. |
StringCheck |
hasFileWhich()
Creates an
StringCheck property check for the file of the
URL argument. |
StringCheck |
hasHostWhich()
Creates an
StringCheck property check for the host of the
URL argument. |
StringCheck |
hasPathWhich()
Creates an
StringCheck property check for the path of the
URL argument. |
IntCheck |
hasPortWhich()
|
UrlCheck |
hasProtocol(String protocol)
Checks that the
URL argument has the given protocol, throwing an
exception otherwise. |
StringCheck |
hasProtocolWhich()
Creates an
StringCheck property check for the protocol of the
URL argument. |
StringCheck |
hasQueryWhich()
Creates an
StringCheck property check for the query of the
URL argument. |
StringCheck |
hasRefWhich()
Creates an
StringCheck property check for the reference (or the
anchor) of the URL argument. |
StringCheck |
hasUserInfoWhich()
Creates an
StringCheck property check for the user info of the
URL argument. |
check, checkNull, checkWithCause, hasClass, intPropertyCheck, isEqualTo, isInstanceOf, isNotNull, isNullOr, isSameAs, objectPropertyCheck
checkConversion, me, named, not
public UrlCheck(URL arg)
public UrlCheck hasProtocol(String protocol)
URL
argument has the given protocol, throwing an
exception otherwise.
The message type used for exceptions thrown by this method is
MessageType.ARG_PROTOCOL
.
To create more sophisticated checks using the URL protocol, use the
hasProtocolWhich()
property check.
protocol
- The protocol the URL should haveIllegalArgumentException
- if the URL argument has a protocol different from the given
onepublic StringCheck hasProtocolWhich()
StringCheck
property check for the protocol of the
URL
argument. It can be used to create advanced checks using the
protocol. For example:
Check.that(url).hasProtocolWhich().matches("https?");
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the protocol of this check's URL set as the
argument and an argument name that indicates this fact. If the URL
reference is null
and allowed to be so (like in the above
example), the returned property check is completely disabled, meaning
none of its check methods will throw an exception. An inversion called
before this method is ignored and does not have any
effect on the check methods called on the returned property check.
public StringCheck hasHostWhich()
StringCheck
property check for the host of the
URL
argument. It can be used to create checks using the host. For
example:
Check.that(url).hasHostWhich().endsWith(".ch");
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the host of this check's URL set as the argument
and an argument name that indicates this fact. If the URL reference is
null
and allowed to be so, the returned property check is
completely disabled, meaning none of its check methods will throw an
exception. An inversion called before this method is ignored and does
not have any effect on the check methods called on the
returned property check.
public IntCheck hasPortWhich()
IntCheck
property check for the port of the
URL
argument. It can be used to create checks using the port. For
example:
Check.that(url).hasPortWhich().is(80);
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the port of this check's URL set as the argument
and an argument name that indicates this fact. If the URL reference is
null
and allowed to be so, the returned property check is
completely disabled, meaning none of its check methods will throw an
exception. An inversion called before this method is ignored and does
not have any effect on the check methods called on the
returned property check.
URL.getPort()
public StringCheck hasFileWhich()
StringCheck
property check for the file of the
URL
argument.
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the file of this check's URL set as the argument
and an argument name that indicates this fact. If the URL reference is
null
and allowed to be so, the returned property check is
completely disabled, meaning none of its check methods will throw an
exception. An inversion called before this method is ignored and does
not have any effect on the check methods called on the
returned property check.
URL.getFile()
public StringCheck hasQueryWhich()
StringCheck
property check for the query of the
URL
argument.
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the query of this check's URL set as the argument
and an argument name that indicates this fact. If the URL reference is
null
and allowed to be so, the returned property check is
completely disabled, meaning none of its check methods will throw an
exception. An inversion called before this method is ignored and does
not have any effect on the check methods called on the
returned property check.
URL.getQuery()
public StringCheck hasAuthorityWhich()
StringCheck
property check for the authority of the
URL
argument.
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the authority of this check's URL set as the
argument and an argument name that indicates this fact. If the URL
reference is null
and allowed to be so, the returned
property check is completely disabled, meaning none of its check methods
will throw an exception. An inversion called before this method is
ignored and does not have any effect on the check
methods called on the returned property check.
URL.getAuthority()
public StringCheck hasPathWhich()
StringCheck
property check for the path of the
URL
argument.
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the path of this check's URL set as the argument
and an argument name that indicates this fact. If the URL reference is
null
and allowed to be so, the returned property check is
completely disabled, meaning none of its check methods will throw an
exception. An inversion called before this method is ignored and does
not have any effect on the check methods called on the
returned property check.
URL.getPath()
public StringCheck hasUserInfoWhich()
StringCheck
property check for the user info of the
URL
argument.
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the user info of this check's URL set as the
argument and an argument name that indicates this fact. If the URL
reference is null
and allowed to be so, the returned
property check is completely disabled, meaning none of its check methods
will throw an exception. An inversion called before this method is
ignored and does not have any effect on the check
methods called on the returned property check.
URL.getUserInfo()
public StringCheck hasRefWhich()
StringCheck
property check for the reference (or the
anchor) of the URL
argument.
Just like a check method, this method first asserts the non-nullness of the argument, throwing an exception in case of a failure.
The returned check has the reference of this check's URL set as the
argument and an argument name that indicates this fact. If the URL
reference is null
and allowed to be so, the returned
property check is completely disabled, meaning none of its check methods
will throw an exception. An inversion called before this method is
ignored and does not have any effect on the check
methods called on the returned property check.
URL.getRef()
Copyright © 2012–2017 Michael Faes. All rights reserved.