类 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.- 从以下版本开始:
- 2.0.0
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classTestPropertyValues.PairA single name value pair.static classTestPropertyValues.TypeThe type of property source.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 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.
方法详细资料
and
public TestPropertyValues and(String... pairs)
Builder method to add more properties.- 参数:
pairs- the property pairs to add- 返回:
- 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.- 参数:
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 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.- 参数:
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.- 类型参数:
T- the result type- 参数:
call- the call to make- 返回:
- 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.- 参数:
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 newTestPropertyValueswith 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 newTestPropertyValueswith 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 emptyTestPropertyValuesinstance.- 返回:
- an empty instance