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
Modifier and TypeClassDescriptionstatic final class
A single name value pair.static enum
The type of property source. -
Method Summary
Modifier and TypeMethodDescriptionReturn a newTestPropertyValues
instance with additional entries.Return a newTestPropertyValues
instance with additional entries.Return a newTestPropertyValues
instance with additional entries.Return a newTestPropertyValues
instance with additional entries.and
(Stream<T> stream, Function<T, TestPropertyValues.Pair> mapper) Return a newTestPropertyValues
instance with additional entries.void
applyTo
(ConfigurableApplicationContext context) Add the properties from the underlying map to the environment owned by anApplicationContext
.void
applyTo
(ConfigurableEnvironment environment) Add the properties from the underlying map to the environment.void
applyTo
(ConfigurableEnvironment environment, TestPropertyValues.Type type) Add the properties from the underlying map to the environment using the specified property source type.void
applyTo
(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.<T> T
applyToSystemProperties
(Callable<T> call) Add the properties to thesystem properties
for the duration of thecall
, restoring previous values when the call completes.static TestPropertyValues
empty()
Return an emptyTestPropertyValues
instance.static TestPropertyValues
Return a newTestPropertyValues
with the underlying map populated with the given property pairs.static TestPropertyValues
Return a newTestPropertyValues
with the underlying map populated with the given property pairs.static TestPropertyValues
Return a newTestPropertyValues
with the underlying map populated with the given map entries.static TestPropertyValues
Return a newTestPropertyValues
with the underlying map populated with the given property pairs.static <T> TestPropertyValues
of
(Stream<T> stream, Function<T, TestPropertyValues.Pair> mapper) Return a newTestPropertyValues
with the underlying map populated with the given stream.
-
Method Details
-
and
Return a newTestPropertyValues
instance with additional entries. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
pairs
- the property pairs to add- Returns:
- a new
TestPropertyValues
instance
-
and
Return a newTestPropertyValues
instance with additional entries. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
pairs
- the property pairs to add- Returns:
- a new
TestPropertyValues
instance - Since:
- 2.4.0
-
and
Return a newTestPropertyValues
instance with additional entries. Name-value pairs can be specified with colon (":") or equals ("=") separators.- Parameters:
pairs
- the property pairs to add- Returns:
- a new
TestPropertyValues
instance - Since:
- 2.4.0
-
and
Return a newTestPropertyValues
instance with additional entries.- Parameters:
map
- the map of properties that need to be added to the environment- Returns:
- a new
TestPropertyValues
instance - Since:
- 2.4.0
-
and
Return a newTestPropertyValues
instance 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
TestPropertyValues
instance - 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 ofPropertySource
to 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 ofPropertySource
to be added. SeeTestPropertyValues.Type
name
- the name for the property source
-
applyToSystemProperties
Add the properties to thesystem properties
for the duration of thecall
, restoring previous values when the call completes.- Type Parameters:
T
- the result type- Parameters:
call
- the call to make- Returns:
- the result of the call
-
of
Return a newTestPropertyValues
with 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 newTestPropertyValues
with 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 newTestPropertyValues
with 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 newTestPropertyValues
with 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 newTestPropertyValues
with 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 emptyTestPropertyValues
instance.- Returns:
- an empty instance
-