Package dev.aherscu.qa.testing.utils
Class UriUtils
- java.lang.Object
-
- dev.aherscu.qa.testing.utils.UriUtils
-
public class UriUtils extends Object
URI handling utilities.- Author:
- aherscu
-
-
Constructor Summary
Constructors Constructor Description UriUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
lastSegmentOf(URI url)
Extracts the last segment of the path of specified URL.static List<String>
listOfStringsFrom(List<URI> uris)
static String
passwordFrom(URI url)
Extracts the password from specified URL.static String
pathSegmentFrom(URI url, int n)
Extracts a path segment from specified URL.static URI
quietUriFrom(String url)
Sneakily re-throws theURISyntaxException
thrown byURI
.static URI
stripUserInfoFrom(URI url)
Removes username and password from specified URL.static String
usernameFrom(URI url)
Extracts the user-name from specified URL.
-
-
-
Method Detail
-
lastSegmentOf
public static String lastSegmentOf(URI url)
Extracts the last segment of the path of specified URL. For example, forhttp://somewhere.com/path/to/resource
,resource
would be returned.- Parameters:
url
- the URL- Returns:
- the last segment of the specified URL
-
listOfStringsFrom
public static List<String> listOfStringsFrom(List<URI> uris)
- Parameters:
uris
- the URIs- Returns:
- list of strings from specified list of URIs.
-
passwordFrom
public static String passwordFrom(URI url)
Extracts the password from specified URL. For example, forhttp://jdoe:s3cr3t@somewhere.com/path/to/resource
,s3cr3t
would be returned.- Parameters:
url
- the URL- Returns:
- the password
-
pathSegmentFrom
public static String pathSegmentFrom(URI url, int n)
Extracts a path segment from specified URL.- Parameters:
url
- the URLn
- the index of requested path segment, where the first one is 0- Returns:
- the requested path segment
-
quietUriFrom
public static URI quietUriFrom(String url)
Sneakily re-throws theURISyntaxException
thrown byURI
.- Parameters:
url
- theString
to parse as a URL- Returns:
URL(String)
-
stripUserInfoFrom
public static URI stripUserInfoFrom(URI url)
Removes username and password from specified URL.- Parameters:
url
- the URL- Returns:
- URL without username and password
-
-