- java.lang.Object
-
- org.junitpioneer.jupiter.AbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>
-
- org.junitpioneer.jupiter.SystemPropertyExtension
-
- 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 SystemPropertyExtension extends AbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>
-
-
Constructor Summary
Constructors Constructor Description SystemPropertyExtension()
-
Method Summary
All Methods Static 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<ClearSystemProperty,java.lang.String>clearKeyMapper()(package private) static java.util.PropertiescreateEffectiveClone(java.util.Properties original)A clone of the String values of the passedProperties, including defaults.protected java.lang.StringgetEntry(java.lang.String key)Gets the entry indicated by the specified key.protected java.util.PropertiesprepareToEnterRestorableContext()This implementation uses the "Preemptive swap" strategy.protected voidprepareToExitRestorableContext(java.util.Properties properties)Prepare to exit a restorable context for the entry based environment.protected voidsetEntry(java.lang.String key, java.lang.String value)Sets the entry indicated by the specified key.protected java.util.function.Function<SetSystemProperty,java.lang.String>setKeyMapper()protected java.util.function.Function<SetSystemProperty,java.lang.String>setValueMapper()-
Methods inherited from class org.junitpioneer.jupiter.AbstractEntryBasedExtension
afterAll, afterEach, beforeAll, beforeEach, reportWarning
-
-
-
-
Method Detail
-
clearKeyMapper
protected java.util.function.Function<ClearSystemProperty,java.lang.String> clearKeyMapper()
- Specified by:
clearKeyMapperin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>- Returns:
- Mapper function to get the key from a clear annotation.
-
setKeyMapper
protected java.util.function.Function<SetSystemProperty,java.lang.String> setKeyMapper()
- Specified by:
setKeyMapperin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>- Returns:
- Mapper function to get the key from a set annotation.
-
setValueMapper
protected java.util.function.Function<SetSystemProperty,java.lang.String> setValueMapper()
- Specified by:
setValueMapperin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>- Returns:
- Mapper function to get the value from a set annotation.
-
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,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>
-
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,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>
-
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,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>
-
prepareToEnterRestorableContext
protected java.util.Properties prepareToEnterRestorableContext()
This implementation uses the "Preemptive swap" strategy.Since
Propertiesallows a wrapped default instance and Object values, cloning is difficult:- It is difficult to tell which values are defaults and which are "top level", thus a clone might contain the same effective values, but be flattened without defaults.
- Object values in a wrapped default instance cannot be accessed without reflection.
The "Preemptive swap" strategy ensure that the original Properties are restored, however complex they were. Any artifacts resulting from a flattened default structure are limited to the context of the test.
See
AbstractEntryBasedExtension.prepareToEnterRestorableContext()for more details.- Specified by:
prepareToEnterRestorableContextin classAbstractEntryBasedExtension<java.lang.String,java.lang.String,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>- Returns:
- The original
System.getProperties()object
-
prepareToExitRestorableContext
protected void prepareToExitRestorableContext(java.util.Properties properties)
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,ClearSystemProperty,SetSystemProperty,RestoreSystemProperties>- Parameters:
properties- A non-nullPropertiesthat contains all entries of the entry environment.
-
createEffectiveClone
static java.util.Properties createEffectiveClone(java.util.Properties original)
A clone of the String values of the passedProperties, including defaults.The clone will have the same effective values, but may not use the same nested structure as the original. Object values, which are technically possible, are not included in the clone.
- Parameters:
original-Propertiesto be cloned.- Returns:
- A new
Propertiesinstance containing the same effective entries as the original.
-
-