- java.lang.Object
-
- org.junitpioneer.jupiter.AbstractEntryBasedExtension<java.lang.String,java.lang.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<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.concurrent.atomic.AtomicBooleanREPORTED_WARNING(package private) static java.lang.StringWARNING_KEY(package private) static java.lang.StringWARNING_VALUE
-
Constructor Summary
Constructors Constructor Description EnvironmentVariableExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearEntry(java.lang.String key)Removes the entry indicated by the specified key.protected java.util.function.Function<ClearEnvironmentVariable,java.lang.String>clearKeyMapper()protected java.lang.StringgetEntry(java.lang.String key)Gets the entry indicated by the specified key.protected java.util.PropertiesprepareToEnterRestorableContext()This implementation uses the "Post swap" strategy, returning a clone of the environment variables which will be restored inAbstractEntryBasedExtension.prepareToExitRestorableContext(java.util.Properties).protected voidprepareToExitRestorableContext(java.util.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 voidsetEntry(java.lang.String key, java.lang.String value)Sets the entry indicated by the specified key.protected java.util.function.Function<SetEnvironmentVariable,java.lang.String>setKeyMapper()protected java.util.function.Function<SetEnvironmentVariable,java.lang.String>setValueMapper()-
Methods inherited from class org.junitpioneer.jupiter.AbstractEntryBasedExtension
afterAll, afterEach, beforeAll, beforeEach
-
-
-
-
Field Detail
-
REPORTED_WARNING
static final java.util.concurrent.atomic.AtomicBoolean REPORTED_WARNING
-
WARNING_KEY
static final java.lang.String WARNING_KEY
-
WARNING_VALUE
static final java.lang.String WARNING_VALUE
- See Also:
- Constant Field Values
-
-
Method Detail
-
clearKeyMapper
protected java.util.function.Function<ClearEnvironmentVariable,java.lang.String> clearKeyMapper()
- Specified by:
clearKeyMapperin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>- Returns:
- Mapper function to get the key from a clear annotation.
-
setKeyMapper
protected java.util.function.Function<SetEnvironmentVariable,java.lang.String> setKeyMapper()
- Specified by:
setKeyMapperin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>- Returns:
- Mapper function to get the key from a set annotation.
-
setValueMapper
protected java.util.function.Function<SetEnvironmentVariable,java.lang.String> setValueMapper()
- Specified by:
setValueMapperin classAbstractEntryBasedExtension<java.lang.String,java.lang.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.- Overrides:
reportWarningin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>
-
clearEntry
protected void clearEntry(java.lang.String key)
Description copied from class:AbstractEntryBasedExtensionRemoves the entry indicated by the specified key.- Specified by:
clearEntryin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>
-
getEntry
protected java.lang.String getEntry(java.lang.String key)
Description copied from class:AbstractEntryBasedExtensionGets the entry indicated by the specified key.- Specified by:
getEntryin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>
-
setEntry
protected void setEntry(java.lang.String key, java.lang.String value)Description copied from class:AbstractEntryBasedExtensionSets the entry indicated by the specified key.- Specified by:
setEntryin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>
-
prepareToEnterRestorableContext
protected java.util.Properties prepareToEnterRestorableContext()
This implementation uses the "Post swap" strategy, returning a clone of the environment variables which will be restored inAbstractEntryBasedExtension.prepareToExitRestorableContext(java.util.Properties).See
AbstractEntryBasedExtension.prepareToEnterRestorableContext()for more details.- Specified by:
prepareToEnterRestorableContextin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>- Returns:
- A clone of the current environment variables, as a
Propertiesobject.
-
prepareToExitRestorableContext
protected void prepareToExitRestorableContext(java.util.Properties restoreMe)
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<java.lang.String,java.lang.String,ClearEnvironmentVariable,SetEnvironmentVariable,RestoreEnvironmentVariables>- Parameters:
restoreMe- A non-nullPropertiesthat contains all entries of the entry environment.
-
-