Class EnvironmentVariableExtension
java.lang.Object
org.junitpioneer.jupiter.AbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>
org.junitpioneer.jupiter.EnvironmentVariableExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension
class EnvironmentVariableExtension
extends AbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final AtomicBoolean(package private) static final String(package private) static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclearEntry(String key) Removes the entry indicated by the specified key.protected Function<ClearEnvironmentVariable, String> protected StringGets the entry indicated by the specified key.protected PropertiesThis implementation uses the "Post swap" strategy, returning a clone of the environment variables which will be restored inAbstractEntryBasedExtension.prepareToExitRestorableContext(Properties).protected voidprepareToExitRestorableContext(Properties restoreMe) Prepare to exit a restorable context for the entry based environment.protected voidreportWarning(org.junit.jupiter.api.extension.ExtensionContext context) Reports a warning about potentially unsafe practices.protected voidSets the entry indicated by the specified key.protected Function<SetEnvironmentVariable, String> protected Function<SetEnvironmentVariable, String> Methods inherited from class AbstractEntryBasedExtension
afterAll, afterEach, beforeAll, beforeEach
-
Field Details
-
REPORTED_WARNING
-
WARNING_KEY
-
WARNING_VALUE
- See Also:
-
-
Constructor Details
-
EnvironmentVariableExtension
EnvironmentVariableExtension()
-
-
Method Details
-
clearKeyMapper
- Specified by:
clearKeyMapperin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>- Returns:
- Mapper function to get the key from a clear annotation.
-
setKeyMapper
- Specified by:
setKeyMapperin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>- Returns:
- Mapper function to get the key from a set annotation.
-
setValueMapper
- Specified by:
setValueMapperin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>- Returns:
- Mapper function to get the value from a set annotation.
-
reportWarning
protected void reportWarning(org.junit.jupiter.api.extension.ExtensionContext context) Description copied from class:AbstractEntryBasedExtensionReports a warning about potentially unsafe practices. -
clearEntry
Description copied from class:AbstractEntryBasedExtensionRemoves the entry indicated by the specified key.- Specified by:
clearEntryin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>
-
getEntry
Description copied from class:AbstractEntryBasedExtensionGets the entry indicated by the specified key.- Specified by:
getEntryin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>
-
setEntry
Description copied from class:AbstractEntryBasedExtensionSets the entry indicated by the specified key.- Specified by:
setEntryin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>
-
prepareToEnterRestorableContext
This implementation uses the "Post swap" strategy, returning a clone of the environment variables which will be restored inAbstractEntryBasedExtension.prepareToExitRestorableContext(Properties).See
AbstractEntryBasedExtension.prepareToEnterRestorableContext()for more details.- Specified by:
prepareToEnterRestorableContextin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>- Returns:
- A clone of the current environment variables, as a
Propertiesobject.
-
prepareToExitRestorableContext
Description copied from class:AbstractEntryBasedExtensionPrepare to exit a restorable context for the entry based environment.The entry environment will be restored to the state passed in as
Properties. ThePropertiesentries must follow the rules for entries of this environment, e.g., environment variables contain only Strings while SystemPropertiesmay contain Objects.- Specified by:
prepareToExitRestorableContextin classAbstractEntryBasedExtension<String, String, ClearEnvironmentVariable, SetEnvironmentVariable, RestoreEnvironmentVariables>- Parameters:
restoreMe- A non-nullPropertiesthat contains all entries of the entry environment.
-