Package org.springframework.mock.env

# Class MockEnvironment

java.lang.Object
org.springframework.core.env.AbstractEnvironment
org.springframework.mock.env.MockEnvironment

All Implemented Interfaces:
  `org.springframework.core.env.ConfigurableEnvironment`, `org.springframework.core.env.ConfigurablePropertyResolver`, `org.springframework.core.env.Environment`, `org.springframework.core.env.PropertyResolver`

public class MockEnvironment extends org.springframework.core.env.AbstractEnvironment
Simple `ConfigurableEnvironment` implementation exposing `setProperty(java.lang.String, java.lang.Object)` and `withProperty(java.lang.String, java.lang.Object)` methods for testing purposes.

Since:
  3.2
Author:
  Chris Beams, Sam Brannen
See Also:
  - `MockPropertySource`

## Field Summary

### Fields inherited from class org.springframework.core.env.AbstractEnvironment

`ACTIVE_PROFILES_PROPERTY_NAME, DEFAULT_PROFILES_PROPERTY_NAME, IGNORE_GETENV_PROPERTY_NAME, logger, RESERVED_DEFAULT_PROFILE_NAME`

## Constructor Summary

Constructors
Constructor
Description
`MockEnvironment()`
Create a new `MockEnvironment` with a single `MockPropertySource`.

## Method Summary

Modifier and Type
Method
Description
`void`
`setProperty(String name, Object value)`
Set a property on the underlying `MockPropertySource` for this environment.
`void`
`setProperty(String name, String value)`
Set a property on the underlying `MockPropertySource` for this environment.
`MockEnvironment`
`withProperty(String name, Object value)`
Convenient synonym for `setProperty(String, Object)` that returns the current instance.
`MockEnvironment`
`withProperty(String name, String value)`
Convenient synonym for `setProperty(String, String)` that returns the current instance.

### Methods inherited from class org.springframework.core.env.AbstractEnvironment

`acceptsProfiles, acceptsProfiles, addActiveProfile, containsProperty, createPropertyResolver, customizePropertySources, doGetActiveProfiles, doGetActiveProfilesProperty, doGetDefaultProfiles, doGetDefaultProfilesProperty, getActiveProfiles, getConversionService, getDefaultProfiles, getProperty, getProperty, getProperty, getProperty, getPropertyResolver, getPropertySources, getRequiredProperty, getRequiredProperty, getReservedDefaultProfiles, getSystemEnvironment, getSystemProperties, isProfileActive, merge, resolvePlaceholders, resolveRequiredPlaceholders, setActiveProfiles, setConversionService, setDefaultProfiles, setEscapeCharacter, setIgnoreUnresolvableNestedPlaceholders, setPlaceholderPrefix, setPlaceholderSuffix, setRequiredProperties, setValueSeparator, suppressGetenvAccess, toString, validateProfile, validateRequiredProperties`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.core.env.Environment

`matchesProfiles`

## Constructor Details

### MockEnvironment

public MockEnvironment()
Create a new `MockEnvironment` with a single `MockPropertySource`.

## Method Details

### setProperty

public void setProperty(String name, Object value)
Set a property on the underlying `MockPropertySource` for this environment.

Since:
  6.2.8
See Also:
  - `MockPropertySource.setProperty(String, Object)`

### setProperty

public void setProperty(String name, String value)
Set a property on the underlying `MockPropertySource` for this environment.

See Also:
  - `setProperty(String, Object)`

### withProperty

public MockEnvironment withProperty(String name, Object value)
Convenient synonym for `setProperty(String, Object)` that returns the current instance.

Useful for method chaining and fluent-style use.

Returns:
  this `MockEnvironment` instance
Since:
  6.2.8
See Also:
  - `MockPropertySource.withProperty(String, Object)`

### withProperty

public MockEnvironment withProperty(String name, String value)
Convenient synonym for `setProperty(String, String)` that returns the current instance.

Useful for method chaining and fluent-style use.

Returns:
  this `MockEnvironment` instance
See Also:
  - `withProperty(String, Object)`