类 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 SpringEnvironment
or to thesystem environment
.- 从以下版本开始:
- 2.0.0
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
TestPropertyValues.Pair
A single name value pair.static class
TestPropertyValues.Type
The type of property source.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 TestPropertyValues
and(String... pairs)
Builder method to add more properties.void
applyTo(org.springframework.context.ConfigurableApplicationContext context)
Add the properties from the underlying map to the environment owned by anApplicationContext
.void
applyTo(org.springframework.core.env.ConfigurableEnvironment environment)
Add the properties from the underlying map to the environment.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.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.<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
of(Iterable<String> pairs)
Return a newTestPropertyValues
with the underlying map populated with the given property pairs.static TestPropertyValues
of(String... pairs)
Return a newTestPropertyValues
with the underlying map populated with the given property pairs.static TestPropertyValues
of(Stream<String> pairs)
Return a newTestPropertyValues
with the underlying map populated with the given property pairs.
方法详细资料
and
public TestPropertyValues and(String... pairs)
Builder method to add more properties.- 参数:
pairs
- the property pairs to add- 返回:
- a new
TestPropertyValues
instance
applyTo
public void applyTo(org.springframework.context.ConfigurableApplicationContext context)
Add the properties from the underlying map to the environment owned by anApplicationContext
.- 参数:
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
.- 参数:
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.- 参数:
environment
- the environment that needs to be modifiedtype
- the type ofPropertySource
to 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.- 参数:
environment
- the environment that needs to be modifiedtype
- the type ofPropertySource
to be added. SeeTestPropertyValues.Type
name
- the name for the property source
applyToSystemProperties
public <T> T applyToSystemProperties(Callable<T> call)
Add the properties to thesystem properties
for the duration of thecall
, restoring previous values when the call completes.- 类型参数:
T
- the result type- 参数:
call
- the call to make- 返回:
- the result of the call
of
public static TestPropertyValues of(String... pairs)
Return a newTestPropertyValues
with the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.- 参数:
pairs
- the name-value pairs for properties that need to be added to the environment- 返回:
- the new instance
of
public static TestPropertyValues of(Iterable<String> pairs)
Return a newTestPropertyValues
with the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.- 参数:
pairs
- the name-value pairs for properties that need to be added to the environment- 返回:
- the new instance
of
public static TestPropertyValues of(Stream<String> pairs)
Return a newTestPropertyValues
with the underlying map populated with the given property pairs. Name-value pairs can be specified with colon (":") or equals ("=") separators.- 参数:
pairs
- the name-value pairs for properties that need to be added to the environment- 返回:
- the new instance
empty
public static TestPropertyValues empty()
Return an emptyTestPropertyValues
instance.- 返回:
- an empty instance