Package org.springframework.mock.env
Class 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");- Since:
- 3.1
- Author:
- Chris Beams
- See Also:
MockEnvironment
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource
PropertySource.StubPropertySource
Field Summary
Fields Modifier and Type Field Description static StringMOCK_PROPERTIES_PROPERTY_SOURCE_NAME"mockProperties" is the default name forMockPropertySourceinstances not otherwise given an explicit name.Fields inherited from class org.springframework.core.env.PropertySource
logger, name, source
Constructor Summary
Constructors Constructor Description 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)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.Methods inherited from class org.springframework.core.env.MapPropertySource
containsProperty, getProperty, getPropertyNames
Field Detail
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.
Constructor Detail
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.- Parameters:
name- the name of the property source
MockPropertySource
public MockPropertySource(Properties properties)
- Parameters:
properties- the properties to use
MockPropertySource
public MockPropertySource(String name, Properties properties)
Create a newMockPropertySourcewith the given name and backed by the givenPropertiesobject.- Parameters:
name- the name of the property sourceproperties- the properties to use
Method Detail
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.- Returns:
- this
MockPropertySourceinstance