类 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
SimplePropertySource
implementation for use in testing. Accepts a user-providedProperties
object, 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 String
MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
"mockProperties" is the default name forMockPropertySource
instances not otherwise given an explicit name.从类继承的字段 org.springframework.core.env.PropertySource
logger, name, source
构造器概要
构造器 构造器 说明 MockPropertySource()
Create a newMockPropertySource
named "mockProperties" that will maintain its own internalProperties
instance.MockPropertySource(String name)
Create a newMockPropertySource
with the given name that will maintain its own internalProperties
instance.MockPropertySource(String name, Properties properties)
Create a newMockPropertySource
with the given name and backed by the givenProperties
object.MockPropertySource(Properties properties)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
setProperty(String name, Object value)
Set the given property on the underlyingProperties
object.MockPropertySource
withProperty(String name, Object value)
Convenient synonym forsetProperty(java.lang.String, java.lang.Object)
that returns the current instance.从类继承的方法 org.springframework.core.env.PropertiesPropertySource
getPropertyNames
从类继承的方法 org.springframework.core.env.MapPropertySource
containsProperty, getProperty
字段详细资料
MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
public static final String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
"mockProperties" is the default name forMockPropertySource
instances not otherwise given an explicit name.
构造器详细资料
MockPropertySource
public MockPropertySource()
Create a newMockPropertySource
named "mockProperties" that will maintain its own internalProperties
instance.
MockPropertySource
public MockPropertySource(String name)
Create a newMockPropertySource
with the given name that will maintain its own internalProperties
instance.- 参数:
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 newMockPropertySource
with the given name and backed by the givenProperties
object.- 参数:
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 underlyingProperties
object.
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
MockPropertySource
instance