Class MockPropertySource
java.lang.Object
org.springframework.core.env.PropertySource<Map<String,Object>>
 
org.springframework.core.env.EnumerablePropertySource<Map<String,Object>>
 
org.springframework.core.env.MapPropertySource
org.springframework.core.env.PropertiesPropertySource
org.springframework.mock.env.MockPropertySource
Simple 
PropertySource implementation for use in testing. Accepts
 a user-provided Properties object, or if omitted during construction,
 the implementation will initialize its own.
 The setProperty(java.lang.String, java.lang.Object) and withProperty(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:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.springframework.core.env.PropertySourcePropertySource.StubPropertySource
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final String"mockProperties" is the default name forMockPropertySourceinstances not otherwise given an explicit name.Fields inherited from class org.springframework.core.env.PropertySourcelogger, name, source
- 
Constructor SummaryConstructorsConstructorDescriptionCreate 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 SummaryModifier and TypeMethodDescriptionvoidsetProperty(String name, Object value) Set the given property on the underlyingPropertiesobject.withProperty(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.PropertiesPropertySourcegetPropertyNamesMethods inherited from class org.springframework.core.env.MapPropertySourcecontainsProperty, getProperty
- 
Field Details- 
MOCK_PROPERTIES_PROPERTY_SOURCE_NAME"mockProperties" is the default name forMockPropertySourceinstances not otherwise given an explicit name.- See Also:
 
 
- 
- 
Constructor Details- 
MockPropertySourcepublic MockPropertySource()Create a newMockPropertySourcenamed "mockProperties" that will maintain its own internalPropertiesinstance.
- 
MockPropertySourceCreate a newMockPropertySourcewith the given name that will maintain its own internalPropertiesinstance.- Parameters:
- name- the name of the property source
 
- 
MockPropertySource- Parameters:
- properties- the properties to use
 
- 
MockPropertySourceCreate a newMockPropertySourcewith the given name and backed by the givenPropertiesobject.- Parameters:
- name- the name of the property source
- properties- the properties to use
 
 
- 
- 
Method Details- 
setPropertySet the given property on the underlyingPropertiesobject.
- 
withPropertyConvenient synonym forsetProperty(java.lang.String, java.lang.Object)that returns the current instance.Useful for method chaining and fluent-style use. - Returns:
- this MockPropertySourceinstance
 
 
-