类 MockPropertySource
- java.lang.Object
- org.springframework.core.env.PropertySource<T>
- org.springframework.core.env.EnumerablePropertySource<Map<String,Object>>
- org.springframework.core.env.MapPropertySource
- org.springframework.core.env.PropertiesPropertySource
- org.springframework.mock.env.MockPropertySource
public class MockPropertySource extends PropertiesPropertySource
SimplePropertySourceimplementation for use in testing. Accepts a user-providedPropertiesobject, or if omitted during construction, the implementation will initialize its own. ThesetProperty(java.lang.String, java.lang.Object)andwithProperty(java.lang.String, java.lang.Object)methods are exposed for convenience, for example:PropertySource<?> source = new MockPropertySource().withProperty("foo", "bar");- 从以下版本开始:
- 3.1
- 作者:
- Chris Beams
- 另请参阅:
MockEnvironment
嵌套类概要
从类继承的嵌套类/接口 org.springframework.core.env.PropertySource
PropertySource.StubPropertySource
字段概要
字段 修饰符和类型 字段 说明 static StringMOCK_PROPERTIES_PROPERTY_SOURCE_NAME"mockProperties" is the default name forMockPropertySourceinstances not otherwise given an explicit name.从类继承的字段 org.springframework.core.env.PropertySource
logger, name, source
构造器概要
构造器 构造器 说明 MockPropertySource()Create a newMockPropertySourcenamed "mockProperties" that will maintain its own internalPropertiesinstance.MockPropertySource(String name)Create a newMockPropertySourcewith the given name that will maintain its own internalPropertiesinstance.MockPropertySource(String name, Properties properties)Create a newMockPropertySourcewith the given name and backed by the givenPropertiesobject.MockPropertySource(Properties properties)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidsetProperty(String name, Object value)Set the given property on the underlyingPropertiesobject.MockPropertySourcewithProperty(String name, Object value)Convenient synonym forsetProperty(java.lang.String, java.lang.Object)that returns the current instance.从类继承的方法 org.springframework.core.env.MapPropertySource
containsProperty, getProperty, getPropertyNames
字段详细资料
MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
public static final String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
"mockProperties" is the default name forMockPropertySourceinstances not otherwise given an explicit name.
构造器详细资料
MockPropertySource
public MockPropertySource()
Create a newMockPropertySourcenamed "mockProperties" that will maintain its own internalPropertiesinstance.
MockPropertySource
public MockPropertySource(String name)
Create a newMockPropertySourcewith the given name that will maintain its own internalPropertiesinstance.- 参数:
name- the name of the property source
MockPropertySource
public MockPropertySource(Properties properties)
- 参数:
properties- the properties to use
MockPropertySource
public MockPropertySource(String name, Properties properties)
Create a newMockPropertySourcewith the given name and backed by the givenPropertiesobject.- 参数:
name- the name of the property sourceproperties- the properties to use
方法详细资料
setProperty
public void setProperty(String name, Object value)
Set the given property on the underlyingPropertiesobject.
withProperty
public MockPropertySource withProperty(String name, Object value)
Convenient synonym forsetProperty(java.lang.String, java.lang.Object)that returns the current instance. Useful for method chaining and fluent-style use.- 返回:
- this
MockPropertySourceinstance