public class MockPropertySource extends PropertiesPropertySource
PropertySource
implementation for use in testing. Accepts
a user-provided <code>Properties</code> 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");
MockEnvironment
PropertySource.StubPropertySource
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
"mockProperties" is the default name for
MockPropertySource instances not
otherwise given an explicit name. |
EMPTY_NAMES_ARRAY, logger
name, source
Constructor and Description |
---|
MockPropertySource()
Create a new
MockPropertySource named "mockProperties"
that will maintain its own internal <code>Properties</code> instance. |
MockPropertySource(java.util.Properties properties)
Create a new
MockPropertySource named "mockProperties"
and backed by the given <code>Properties</code> object. |
MockPropertySource(java.lang.String name)
Create a new
MockPropertySource with the given name that will
maintain its own internal <code>Properties</code> instance. |
MockPropertySource(java.lang.String name,
java.util.Properties properties)
Create a new
MockPropertySource with the given name and backed by the given
<code>Properties</code> object. |
Modifier and Type | Method and Description |
---|---|
void |
setProperty(java.lang.String name,
java.lang.Object value)
Set the given property on the underlying <code>Properties</code> 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. |
getProperty, getPropertyNames
containsProperty
public static final java.lang.String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME
MockPropertySource
instances not
otherwise given an explicit name.public MockPropertySource()
MockPropertySource
named "mockProperties"
that will maintain its own internal <code>Properties</code> instance.public MockPropertySource(java.lang.String name)
MockPropertySource
with the given name that will
maintain its own internal <code>Properties</code> instance.name
- the name of the property sourcepublic MockPropertySource(java.util.Properties properties)
MockPropertySource
named "mockProperties"
and backed by the given <code>Properties</code> object.properties
- the properties to usepublic MockPropertySource(java.lang.String name, java.util.Properties properties)
MockPropertySource
with the given name and backed by the given
<code>Properties</code> object.name
- the name of the property sourceproperties
- the properties to usepublic void setProperty(java.lang.String name, java.lang.Object value)
public MockPropertySource withProperty(java.lang.String name, java.lang.Object value)
setProperty(java.lang.String, java.lang.Object)
that returns the current instance.
Useful for method chaining and fluent-style use.MockPropertySource
instance