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 Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA single name value pair.static enumThe type of property source. -
Method Summary
Modifier 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(Stream<T> stream, Function<T, 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> 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(Stream<T> stream, Function<T, TestPropertyValues.Pair> mapper) Return a newTestPropertyValueswith the underlying map populated with the given stream.
-
Method Details
-
and
Return 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
-
and
Return 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
-
and
Return 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
-
and
Return 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
-
and
Return a newTestPropertyValuesinstance with additional entries.- Type Parameters:
T- the stream element type- Parameters:
stream- the elements that need to be added to the environmentmapper- a mapper function to convert an element from the stream into aTestPropertyValues.Pair- Returns:
- a new
TestPropertyValuesinstance - Since:
- 2.4.0
-
applyTo
Add the properties from the underlying map to the environment owned by anApplicationContext.- Parameters:
context- the context with an environment to modify
-
applyTo
Add the properties from the underlying map to the environment. The default property source used isMapPropertySource.- Parameters:
environment- the environment that needs to be modified
-
applyTo
Add the properties from the underlying map to the environment using the specified property source type.- Parameters:
environment- the environment that needs to be modifiedtype- the type ofPropertySourceto be added. SeeTestPropertyValues.Type
-
applyTo
Add 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 modifiedtype- the type ofPropertySourceto be added. SeeTestPropertyValues.Typename- the name for the property source
-
applyToSystemProperties
Add 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
-
applyToSystemProperties
Add 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
-
of
Return 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
-
of
Return 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
-
of
Return 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
-
of
Return 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
-
of
public static <T> TestPropertyValues of(Stream<T> stream, Function<T, 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 environmentmapper- a mapper function to convert an element from the stream into aTestPropertyValues.Pair- Returns:
- the new instance
-
empty
Return an emptyTestPropertyValuesinstance.- Returns:
- an empty instance
-