@API(status=INTERNAL, since="1.0") public final class PackageUtils extends java.lang.Object
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!
| Modifier and Type | Method | Description |
|---|---|---|
static void |
assertPackageNameIsValid(java.lang.String packageName) |
Assert that the supplied package name is valid in terms of Java syntax.
|
static java.util.Optional<java.lang.String> |
getAttribute(java.lang.Class<?> type,
java.lang.String name) |
Get the value of the specified attribute name, specified as a string,
or an empty
Optional if the attribute was not found. |
static java.util.Optional<java.lang.String> |
getAttribute(java.lang.Class<?> type,
java.util.function.Function<java.lang.Package,java.lang.String> function) |
Get the package attribute for the supplied
type using the
supplied function. |
public static void assertPackageNameIsValid(java.lang.String packageName)
Note: this method does not actually verify if the named package exists in the classpath.
The default package is represented by an empty string ("").
packageName - the package name to validatePreconditionViolationException - if the supplied package name is
null, contains only whitespace, or contains parts that are not
valid in terms of Java syntax (e.g., containing keywords such as
void, import, etc.)SourceVersion.isName(CharSequence)public static java.util.Optional<java.lang.String> getAttribute(java.lang.Class<?> type,
java.util.function.Function<java.lang.Package,java.lang.String> function)
type using the
supplied function.
This method only returns a non-empty Optional value holder
if the class loader for the supplied type created a Package
object and the supplied function does not return null when
applied.
type - the type to get the package attribute forfunction - a function that computes the package attribute value
(e.g., Package::getImplementationTitle); never nullOptional containing the attribute value; never
null but potentially emptyPreconditionViolationException - if the supplied type or function
is nullClass.getPackage(),
Package.getImplementationTitle(),
Package.getImplementationVersion()public static java.util.Optional<java.lang.String> getAttribute(java.lang.Class<?> type,
java.lang.String name)
Optional 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.
type - the type to get the attribute forname - the attribute name as a stringOptional containing the attribute value; never
null but potentially emptyPreconditionViolationException - if the supplied type is
null or the specified name is blankManifest.getMainAttributes()