public class

MockPropertySource

extends PropertiesPropertySource
java.lang.Object
   ↳ org.springframework.core.env.PropertySource<T>
     ↳ org.springframework.core.env.EnumerablePropertySource<T>
       ↳ org.springframework.core.env.MapPropertySource
         ↳ org.springframework.core.env.PropertiesPropertySource
           ↳ org.springframework.mock.env.MockPropertySource

Class Overview

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(String, String) and withProperty(String, String) methods are exposed for convenience, for example:

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

See Also
  • MockEnvironment

Summary

Constants
String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME {@value } is the default name for MockPropertySource instances not otherwise given an explicit name.
[Expand]
Inherited Fields
From class org.springframework.core.env.EnumerablePropertySource
From class org.springframework.core.env.PropertySource
Public Constructors
MockPropertySource()
Create a new MockPropertySource named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME} that will maintain its own internal Properties instance.
MockPropertySource(String name)
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(String name, Properties properties)
Create a new MockPropertySource with with the given name and backed by the given Properties object
Public Methods
void setProperty(String key, String value)
Set the given property on the underlying Properties object.
MockPropertySource withProperty(String key, String value)
Convenient synonym for setProperty(String, String) that returns the current instance.
[Expand]
Inherited Methods
From class org.springframework.core.env.MapPropertySource
From class org.springframework.core.env.EnumerablePropertySource
From class org.springframework.core.env.PropertySource
From class java.lang.Object

Constants

public static final String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME

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

Constant Value: "mockProperties"

Public Constructors

public MockPropertySource ()

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

public MockPropertySource (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

public MockPropertySource (Properties properties)

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

Parameters
properties the properties to use

public MockPropertySource (String name, 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

Public Methods

public void setProperty (String key, String value)

Set the given property on the underlying Properties object.

public MockPropertySource withProperty (String key, String value)

Convenient synonym for setProperty(String, String) that returns the current instance. Useful for method chaining and fluent-style use.

Returns