Package org.junit.platform.commons.util
Class PackageUtils
java.lang.Object
org.junit.platform.commons.util.PackageUtils
Collection of utilities for working with packages.
DISCLAIMER
These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Collection of utilities for working with qualified names in Java. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertPackageNameIsValid
(String packageName) Assert that the supplied package name is valid in terms of Java syntax.getAttribute
(Class<?> type, String name) Get the value of the specified attribute name, specified as a string, or an emptyOptional
if the attribute was not found.getAttribute
(Class<?> type, Function<Package, String> function) Get the package attribute for the suppliedtype
using the suppliedfunction
.
-
Field Details
-
DEFAULT_PACKAGE_NAME
- See Also:
-
DOT_PATTERN
Compiled"\."
pattern used to split canonical package (and type) names.
-
-
Constructor Details
-
PackageUtils
private PackageUtils()
-
-
Method Details
-
assertPackageNameIsValid
Assert that the supplied package name is valid in terms of Java syntax.Note: this method does not actually verify if the named package exists in the classpath.
The default package is represented by an empty string (
""
).- Parameters:
packageName
- the package name to validate- Throws:
PreconditionViolationException
- if the supplied package name isnull
, contains only whitespace, or contains parts that are not valid in terms of Java syntax (e.g., containing keywords such asvoid
,import
, etc.)- See Also:
-
getAttribute
Get the package attribute for the suppliedtype
using the suppliedfunction
.This method only returns a non-empty
Optional
value holder if the class loader for the supplied type created aPackage
object and the supplied function does not returnnull
when applied.- Parameters:
type
- the type to get the package attribute forfunction
- a function that computes the package attribute value (e.g.,Package::getImplementationTitle
); nevernull
- Returns:
- an
Optional
containing the attribute value; nevernull
but potentially empty - Throws:
PreconditionViolationException
- if the supplied type or function isnull
- See Also:
-
getAttribute
Get the value of the specified attribute name, specified as a string, or an emptyOptional
if the attribute was not found. The attribute name is case-insensitive.This method also returns an empty
Optional
value holder if any exception is caught while loading the manifest file via the JAR file of the specified type.- Parameters:
type
- the type to get the attribute forname
- the attribute name as a string- Returns:
- an
Optional
containing the attribute value; nevernull
but potentially empty - Throws:
PreconditionViolationException
- if the supplied type isnull
or the specified name is blank- See Also:
-