Class TestPropertyValues
- java.lang.Object
- org.springframework.boot.test.util.TestPropertyValues
public final class TestPropertyValues extends Object
Test utilities for adding properties. Properties can be applied to a SpringEnvironmentor to thesystem environment.- Since:
- 2.0.0
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTestPropertyValues.PairA single name value pair.static classTestPropertyValues.TypeThe type of property source.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TestPropertyValuesand(String... pairs)Builder method to add more properties.voidapplyTo(org.springframework.context.ConfigurableApplicationContext context)Add the properties from the underlying map to the environment owned by anApplicationContext.voidapplyTo(org.springframework.core.env.ConfigurableEnvironment environment)Add the properties from the underlying map to the environment.voidapplyTo(org.springframework.core.env.ConfigurableEnvironment environment, TestPropertyValues.Type type)Add the properties from the underlying map to the environment using the specified property source type.voidapplyTo(org.springframework.core.env.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> TapplyToSystemProperties(Callable<T> call)Add the properties to thesystem propertiesfor the duration of thecall, restoring previous values when the call completes.static TestPropertyValuesempty()Return an emptyTestPropertyValuesinstance.static TestPropertyValuesof(Iterable<String> pairs)Return a newTestPropertyValueswith the underlying map populated with the given property pairs.static TestPropertyValuesof(String... pairs)Return a newTestPropertyValueswith the underlying map populated with the given property pairs.static TestPropertyValuesof(Stream<String> pairs)Return a newTestPropertyValueswith the underlying map populated with the given property pairs.
Method Detail
and
public TestPropertyValues and(String... pairs)
Builder method to add more properties.- Parameters:
pairs- the property pairs to add- Returns:
- a new
TestPropertyValuesinstance
applyTo
public void applyTo(org.springframework.context.ConfigurableApplicationContext context)
Add the properties from the underlying map to the environment owned by anApplicationContext.- Parameters:
context- the context with an environment to modify
applyTo
public void applyTo(org.springframework.core.env.ConfigurableEnvironment environment)
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
public void applyTo(org.springframework.core.env.ConfigurableEnvironment environment, TestPropertyValues.Type type)
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
public void applyTo(org.springframework.core.env.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.- Parameters:
environment- the environment that needs to be modifiedtype- the type ofPropertySourceto be added. SeeTestPropertyValues.Typename- the name for the property source
applyToSystemProperties
public <T> T applyToSystemProperties(Callable<T> call)
Add the properties to thesystem propertiesfor 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
public static TestPropertyValues of(String... pairs)
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
public static TestPropertyValues of(Iterable<String> pairs)
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
public static TestPropertyValues of(Stream<String> pairs)
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
empty
public static TestPropertyValues empty()
Return an emptyTestPropertyValuesinstance.- Returns:
- an empty instance