org.springframework.mock.env
Class MockPropertySource

java.lang.Object
  extended by org.springframework.core.env.PropertySource<T>
      extended by org.springframework.core.env.EnumerablePropertySource<java.util.Map<java.lang.String,java.lang.Object>>
          extended by org.springframework.core.env.MapPropertySource
              extended by org.springframework.core.env.PropertiesPropertySource
                  extended by org.springframework.mock.env.MockPropertySource

public class MockPropertySource
extends PropertiesPropertySource

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:
MockEnvironment

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource
PropertySource.StubPropertySource
 
Field Summary
static java.lang.String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
          "mockProperties" is the default name for MockPropertySource instances not otherwise given an explicit name.
 
Fields inherited from class org.springframework.core.env.EnumerablePropertySource
EMPTY_NAMES_ARRAY, logger
 
Fields inherited from class org.springframework.core.env.PropertySource
name, source
 
Constructor Summary
MockPropertySource()
          Create a new MockPropertySource named "mockProperties" that will maintain its own internal Properties instance.
MockPropertySource(java.util.Properties properties)
          Create a new MockPropertySource named "mockProperties" and backed by the given Properties object.
MockPropertySource(java.lang.String name)
          Create a new MockPropertySource with the given name that will maintain its own internal Properties instance.
MockPropertySource(java.lang.String name, java.util.Properties properties)
          Create a new MockPropertySource with with the given name and backed by the given Properties object
 
Method Summary
 void setProperty(java.lang.String name, java.lang.Object value)
          Set the given property on the underlying Properties object.
 MockPropertySource withProperty(java.lang.String name, java.lang.Object value)
          Convenient synonym for setProperty(java.lang.String, java.lang.Object) that returns the current instance.
 
Methods inherited from class org.springframework.core.env.MapPropertySource
getProperty, getPropertyNames
 
Methods inherited from class org.springframework.core.env.EnumerablePropertySource
containsProperty
 
Methods inherited from class org.springframework.core.env.PropertySource
equals, getName, getSource, hashCode, named, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MOCK_PROPERTIES_PROPERTY_SOURCE_NAME

public static final java.lang.String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
"mockProperties" is the default name for MockPropertySource instances not otherwise given an explicit name.

See Also:
MockPropertySource(), MockPropertySource(String), Constant Field Values
Constructor Detail

MockPropertySource

public MockPropertySource()
Create a new MockPropertySource named "mockProperties" that will maintain its own internal Properties instance.


MockPropertySource

public MockPropertySource(java.lang.String name)
Create a new MockPropertySource with the given name that will maintain its own internal Properties instance.

Parameters:
name - the name of the property source

MockPropertySource

public MockPropertySource(java.util.Properties properties)
Create a new MockPropertySource named "mockProperties" and backed by the given Properties object.

Parameters:
properties - the properties to use

MockPropertySource

public MockPropertySource(java.lang.String name,
                          java.util.Properties properties)
Create a new MockPropertySource with with the given name and backed by the given Properties object

Parameters:
name - the name of the property source
properties - the properties to use
Method Detail

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Set the given property on the underlying Properties object.


withProperty

public MockPropertySource withProperty(java.lang.String name,
                                       java.lang.Object value)
Convenient synonym for setProperty(java.lang.String, java.lang.Object) that returns the current instance. Useful for method chaining and fluent-style use.

Returns:
this MockPropertySource instance