spring-framework / org.springframework.mock.env / MockPropertySource

MockPropertySource

open class MockPropertySource : 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 and #withProperty methods are exposed for convenience, for example:

PropertySource<?> source = new MockPropertySource().withProperty("foo", "bar");  

Author
Chris Beams

Since
3.1

See Also
org.springframework.mock.env.MockEnvironment

Constructors

<init>

MockPropertySource()

Create a new MockPropertySource named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME} that will maintain its own internal Properties instance.

MockPropertySource(name: String)

Create a new MockPropertySource with the given name that will maintain its own internal Properties instance.

MockPropertySource(properties: Properties)

Create a new MockPropertySource named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME} and backed by the given Properties object.

MockPropertySource(name: String, properties: Properties)

Create a new MockPropertySource with the given name and backed by the given Properties object.

Properties

MOCK_PROPERTIES_PROPERTY_SOURCE_NAME

static val MOCK_PROPERTIES_PROPERTY_SOURCE_NAME: String

{@value} is the default name for MockPropertySource instances not otherwise given an explicit name.

Functions

setProperty

open fun setProperty(name: String, value: Any): Unit

Set the given property on the underlying Properties object.

withProperty

open fun withProperty(name: String, value: Any): MockPropertySource

Convenient synonym for #setProperty that returns the current instance. Useful for method chaining and fluent-style use.