Top Description Fields Constructors Methods
org.junit.platform.commons.util

public final Class PackageUtils

extends Object
Class Inheritance
Annotations
@API
status:INTERNAL
since:1.0
Static Imports
org.apiguardian.api.API.Status.INTERNAL

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

Field Summary

Modifier and TypeField and Description
public static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Optional<String>

Returns:

an Optional containing the attribute value; never null but potentially empty
getAttribute
(Class<?>
the type to get the package attribute for
type
,
Function<Package, String>
a function that computes the package attribute value (e.g., Package::getImplementationTitle); never null
function
)

Get the package attribute for the supplied type using the supplied function.

public static Optional<String>

Returns:

an Optional containing the attribute value; never null but potentially empty
getAttribute
(Class<?>
the type to get the attribute for
type
,
String
the attribute name as a string
name
)

Get the value of the specified attribute name, specified as a string, or an empty Optional if the attribute was not found.

public static Optional<String>
getModuleOrImplementationVersion(Class<?> type)

Get the module or implementation version for the supplied type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_PACKAGE_NAMEback to summary
public static final String DEFAULT_PACKAGE_NAME

Constructor Detail

PackageUtilsback to summary
private PackageUtils()

Method Detail

getAttributeback to summary
public static Optional<String> getAttribute(Class<?> type, Function<Package, String> function)

Get the package attribute for the supplied 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.

Parameters
type:Class<?>

the type to get the package attribute for

function:Function<Package, String>

a function that computes the package attribute value (e.g., Package::getImplementationTitle); never null

Returns:Optional<String>

an Optional containing the attribute value; never null but potentially empty

Exceptions
PreconditionViolationException:
if the supplied type or function is null
See Also
Class#getPackage(), Package#getImplementationTitle(), Package#getImplementationVersion()
getAttributeback to summary
public static Optional<String> getAttribute(Class<?> type, String name)

Get the value of the specified attribute name, specified as a string, or an empty 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.

Parameters
type:Class<?>

the type to get the attribute for

name:String

the attribute name as a string

Returns:Optional<String>

an Optional containing the attribute value; never null but potentially empty

Exceptions
PreconditionViolationException:
if the supplied type is null or the specified name is blank
See Also
Manifest#getMainAttributes()
getModuleOrImplementationVersionback to summary
public static Optional<String> getModuleOrImplementationVersion(Class<?> type)

Get the module or implementation version for the supplied type.

The former is only available if the type is part of a versioned module on the module path; the latter only if the type is part of a JAR file with a manifest that contains an Implementation-Version attribute.

Annotations
@API
status:INTERNAL
since:1.11
Since
1.11