Class TestPropertyValues
java.lang.Object
org.springframework.boot.test.util.TestPropertyValues
Test utilities for adding properties. Properties can be applied to a Spring
Environment or to the system environment.- Since:
- 2.0.0
- Author:
- Madhura Bhave, Phillip Webb, Stephane Nicoll
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classA single name value pair.static enumThe type of property source.
- 
Method SummaryModifier and TypeMethodDescriptionReturn a newTestPropertyValuesinstance with additional entries.Return a newTestPropertyValuesinstance with additional entries.Return a newTestPropertyValuesinstance with additional entries.Return a newTestPropertyValuesinstance with additional entries.and(@Nullable Stream<T> stream, Function<T, @Nullable TestPropertyValues.Pair> mapper) Return a newTestPropertyValuesinstance with additional entries.voidapplyTo(ConfigurableApplicationContext context) Add the properties from the underlying map to the environment owned by anApplicationContext.voidapplyTo(ConfigurableEnvironment environment) Add the properties from the underlying map to the environment.voidapplyTo(ConfigurableEnvironment environment, TestPropertyValues.Type type) Add the properties from the underlying map to the environment using the specified property source type.voidapplyTo(ConfigurableEnvironment environment, TestPropertyValues.Type type, String name) Add the properties from the underlying map to the environment using the specified property source type and name.voidapplyToSystemProperties(Runnable action) Add the properties to thesystem propertiesfor the duration of theaction, restoring previous values when it completes.<T extends @Nullable Object>
 TapplyToSystemProperties(Callable<T> call) Add the properties to thesystem propertiesfor the duration of thecall, restoring previous values when it completes.static TestPropertyValuesempty()Return an emptyTestPropertyValuesinstance.static TestPropertyValuesReturn a newTestPropertyValueswith the underlying map populated with the given property pairs.static TestPropertyValuesReturn a newTestPropertyValueswith the underlying map populated with the given property pairs.static TestPropertyValuesReturn a newTestPropertyValueswith the underlying map populated with the given map entries.static TestPropertyValuesReturn a newTestPropertyValueswith the underlying map populated with the given property pairs.static <T> TestPropertyValuesof(@Nullable Stream<T> stream, Function<T, @Nullable TestPropertyValues.Pair> mapper) Return a newTestPropertyValueswith the underlying map populated with the given stream.
- 
Method Details- 
andReturn a newTestPropertyValuesinstance with additional entries. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
- pairs- the property pairs to add
- Returns:
- a new TestPropertyValuesinstance
 
- 
andReturn a newTestPropertyValuesinstance with additional entries. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
- pairs- the property pairs to add
- Returns:
- a new TestPropertyValuesinstance
- Since:
- 2.4.0
 
- 
andReturn a newTestPropertyValuesinstance with additional entries. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
- pairs- the property pairs to add
- Returns:
- a new TestPropertyValuesinstance
- Since:
- 2.4.0
 
- 
andReturn a newTestPropertyValuesinstance with additional entries.- Parameters:
- map- the map of properties that need to be added to the environment
- Returns:
- a new TestPropertyValuesinstance
- Since:
- 2.4.0
 
- 
andpublic <T> TestPropertyValues and(@Nullable Stream<T> stream, Function<T, @Nullable TestPropertyValues.Pair> mapper) Return a newTestPropertyValuesinstance with additional entries.- Type Parameters:
- T- the stream element type
- Parameters:
- stream- the elements that need to be added to the environment
- mapper- a mapper function to convert an element from the stream into a- TestPropertyValues.Pair
- Returns:
- a new TestPropertyValuesinstance
- Since:
- 2.4.0
 
- 
applyToAdd the properties from the underlying map to the environment owned by anApplicationContext.- Parameters:
- context- the context with an environment to modify
 
- 
applyToAdd the properties from the underlying map to the environment. The default property source used isMapPropertySource.- Parameters:
- environment- the environment that needs to be modified
 
- 
applyToAdd the properties from the underlying map to the environment using the specified property source type.- Parameters:
- environment- the environment that needs to be modified
- type- the type of- PropertySourceto be added. See- TestPropertyValues.Type
 
- 
applyToAdd the properties from the underlying map to the environment using the specified property source type and name.- Parameters:
- environment- the environment that needs to be modified
- type- the type of- PropertySourceto be added. See- TestPropertyValues.Type
- name- the name for the property source
 
- 
applyToSystemPropertiesAdd the properties to thesystem propertiesfor the duration of theaction, restoring previous values when it completes.- Parameters:
- action- the action to take
- Since:
- 3.0.0
 
- 
applyToSystemPropertiesAdd the properties to thesystem propertiesfor the duration of thecall, restoring previous values when it completes.- Type Parameters:
- T- the result type
- Parameters:
- call- the call to make
- Returns:
- the result of the call
 
- 
ofReturn a newTestPropertyValueswith the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
- pairs- the name-value pairs for properties that need to be added to the environment
- Returns:
- the new instance
 
- 
ofReturn a newTestPropertyValueswith the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
- pairs- the name-value pairs for properties that need to be added to the environment
- Returns:
- the new instance
 
- 
ofReturn a newTestPropertyValueswith the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
- pairs- the name-value pairs for properties that need to be added to the environment
- Returns:
- the new instance
 
- 
ofReturn a newTestPropertyValueswith the underlying map populated with the given map entries.- Parameters:
- map- the map of properties that need to be added to the environment
- Returns:
- the new instance
 
- 
ofpublic static <T> TestPropertyValues of(@Nullable Stream<T> stream, Function<T, @Nullable TestPropertyValues.Pair> mapper) Return a newTestPropertyValueswith the underlying map populated with the given stream.- Type Parameters:
- T- the stream element type
- Parameters:
- stream- the elements that need to be added to the environment
- mapper- a mapper function to convert an element from the stream into a- TestPropertyValues.Pair
- Returns:
- the new instance
 
- 
emptyReturn an emptyTestPropertyValuesinstance.- Returns:
- an empty instance
 
 
-