Skip to content

Commit

Permalink
Introduce MockEnvironment in the spring-test module
Browse files Browse the repository at this point in the history
For legacy reasons, a MockEnvironment implementation already exists in multiple places within Spring's test suite; however, it is not available to the general public.

This commit promotes MockEnvironment to a first-class citizen in the spring-test module, alongside the existing MockPropertySource.

In addition, the following house cleaning has been performed.

 - deleted MockPropertySource from the spring-expression module
 - deleted MockEnvironment from the "spring" integration testing module
 - updated test copies of MockPropertySource and MockEnvironment
 - documented MockEnvironment and MockPropertySource in the testing
   chapter of the reference manual

Issue: SPR-9492
  • Loading branch information
sbrannen committed Jul 28, 2012
1 parent 0329df2 commit f49b22c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,13 +20,14 @@
import org.springframework.core.env.ConfigurableEnvironment;

/**
* Simple {@link ConfigurableEnvironment} implementation exposing a
* Simple {@link ConfigurableEnvironment} implementation exposing
* {@link #setProperty(String, String)} and {@link #withProperty(String, String)}
* methods for testing purposes.
*
* @author Chris Beams
* @since 3.1
* @see MockPropertySource
* @author Sam Brannen
* @since 3.2
* @see org.springframework.mock.env.MockPropertySource
*/
public class MockEnvironment extends AbstractEnvironment {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@
*
* @author Chris Beams
* @since 3.1
* @see MockEnvironment
* @see org.springframework.mock.env.MockEnvironment
*/
public class MockPropertySource extends PropertiesPropertySource {

Expand Down Expand Up @@ -75,7 +75,7 @@ public MockPropertySource(Properties properties) {
}

/**
* Create a new {@code MockPropertySource} with with the given name and backed by the given
* Create a new {@code MockPropertySource} with the given name and backed by the given
* {@link Properties} object
* @param name the {@linkplain #getName() name} of the property source
* @param properties the properties to use
Expand All @@ -100,4 +100,5 @@ public MockPropertySource withProperty(String name, Object value) {
this.setProperty(name, value);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@
*
* @author Chris Beams
* @since 3.1
* @see MockEnvironment
* @see org.springframework.mock.env.MockEnvironment
*/
public class MockPropertySource extends PropertiesPropertySource {

Expand Down Expand Up @@ -75,7 +75,7 @@ public MockPropertySource(Properties properties) {
}

/**
* Create a new {@code MockPropertySource} with with the given name and backed by the given
* Create a new {@code MockPropertySource} with the given name and backed by the given
* {@link Properties} object
* @param name the {@linkplain #getName() name} of the property source
* @param properties the properties to use
Expand All @@ -100,4 +100,5 @@ public MockPropertySource withProperty(String name, Object value) {
this.setProperty(name, value);
return this;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,13 +20,14 @@
import org.springframework.core.env.ConfigurableEnvironment;

/**
* Simple {@link ConfigurableEnvironment} implementation exposing a
* Simple {@link ConfigurableEnvironment} implementation exposing
* {@link #setProperty(String, String)} and {@link #withProperty(String, String)}
* methods for testing purposes.
*
* @author Chris Beams
* @since 3.1
* @see MockPropertySource
* @author Sam Brannen
* @since 3.2
* @see org.springframework.mock.env.MockPropertySource
*/
public class MockEnvironment extends AbstractEnvironment {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@
*
* @author Chris Beams
* @since 3.1
* @see MockEnvironment
* @see org.springframework.mock.env.MockEnvironment
*/
public class MockPropertySource extends PropertiesPropertySource {

Expand Down Expand Up @@ -75,8 +75,8 @@ public MockPropertySource(Properties properties) {
}

/**
* Create a new {@code MockPropertySource} with with the given name and backed by the given
* {@link Properties} object
* Create a new {@code MockPropertySource} with the given name and backed by the given
* {@link Properties} object.
* @param name the {@linkplain #getName() name} of the property source
* @param properties the properties to use
*/
Expand All @@ -100,4 +100,5 @@ public MockPropertySource withProperty(String name, Object value) {
this.setProperty(name, value);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This package contains mock implementations of the
* {@link org.springframework.core.env.Environment Environment} and
* {@link org.springframework.core.env.PropertySource PropertySource}
* abstractions introduced in Spring 3.1.
*
* <p>These <em>mocks</em> are useful for developing <em>out-of-container</em>
* unit tests for code that depends on environment-specific properties.
*/
package org.springframework.mock.env;
46 changes: 23 additions & 23 deletions src/dist/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ Changes in version 3.2 M2 (2012-08-xx)
--------------------------------------

* spring-test module now depends on junit:junit-dep (SPR-6966)
* infer return type of parameterized factory methods (SPR-9493)
* used BufferedInputStream in SimpleMetaDataReader to double performance (SPR-9528)
* added "repeatCount" bean property to Quartz SimpleTriggerFactoryBean (SPR-9521)
* added "jtaTransactionManager" property to Hibernate 4 LocalSessionFactoryBean/Builder (SPR-9480)
* raise RestClientException instead of IllegalArgumentException for unknown status codes
* added "defaultCharset" property to StringHttpMessageConverter (SPR-9487)
* added JacksonObjectMapperFactoryBean for configuring a Jackson ObjectMapper in XML
* added ContentNegotiationManager/ContentNegotiationStrategy to resolve requested media types
* added support for the HTTP PATCH method to Spring MVC and to RestTemplate (SPR-7985)
* enable smart suffix pattern match in @RequestMapping methods (SPR-7632)
* DispatcherPortlet does not forward event exceptions to the render phase by default (SPR-9287)
* add defaultCharset property to StringHttpMessageConverter
* add @ExceptionResolver annotation to detect classes with @ExceptionHandler methods
* move RSS/Atom message converter registration ahead of jackson/jaxb2
* handle BindException in DefaultHandlerExceptionResolver
* parameterize DeferredResult type
* use reflection to instantiate StandardServletAsyncWebRequest
* fix issue with forward before async request processing
* add exclude patterns for mapped interceptors in MVC namespace and MVC Java config
* support content negotiation options in MVC namespace and MVC Java config
* support named dispatchers in MockServletContext (SPR-9587)
* support single, unqualified tx manager in the TestContext framework (SPR-9645)
* support TransactionManagementConfigurer in the TestContext framework (SPR-9604)
* now inferring return type of parameterized factory methods (SPR-9493)
* now using BufferedInputStream in SimpleMetaDataReader to double performance (SPR-9528)
* introduced "repeatCount" property in Quartz SimpleTriggerFactoryBean (SPR-9521)
* introduced "jtaTransactionManager" property in Hibernate 4 LocalSessionFactoryBean/Builder (SPR-9480)
* now raising RestClientException instead of IllegalArgumentException for unknown status codes
* introduced JacksonObjectMapperFactoryBean for configuring a Jackson ObjectMapper in XML
* introduced ContentNegotiationManager/ContentNegotiationStrategy for resolving requested media types
* introduced support for the HTTP PATCH method in Spring MVC and RestTemplate (SPR-7985)
* enabled smart suffix pattern matching in @RequestMapping methods (SPR-7632)
* DispatcherPortlet no longer forwards event exceptions to the render phase by default (SPR-9287)
* introduced "defaultCharset" property in StringHttpMessageConverter (SPR-9487)
* introduced @ExceptionResolver annotation for detecting classes with @ExceptionHandler methods
* moved RSS/Atom message converter registration ahead of jackson/jaxb2
* now handling BindException in DefaultHandlerExceptionResolver
* DeferredResult type is now parameterized
* now using reflection to instantiate StandardServletAsyncWebRequest
* fixed issue with forward before async request processing
* introduced exclude patterns for mapped interceptors in MVC namespace and MVC Java config
* introduced support for content negotiation options in MVC namespace and MVC Java config
* introduced support for named dispatchers in MockServletContext (SPR-9587)
* introduced support for single, unqualified tx manager in the TestContext framework (SPR-9645)
* introduced support for TransactionManagementConfigurer in the TestContext framework (SPR-9604)
* introduced MockEnvironment in the spring-test module (SPR-9492)


Changes in version 3.2 M1 (2012-05-28)
Expand Down
16 changes: 16 additions & 0 deletions src/reference/docbook/testing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@
<section xml:id="mock-objects">
<title>Mock Objects</title>

<section xml:id="mock-objects-env">
<title>Environment</title>

<para>The <literal>org.springframework.mock.env</literal> package
contains mock implementations of the
<interfacename>Environment</interfacename> and
<interfacename>PropertySource</interfacename> abstractions introduced
in Spring 3.1 (see <xref
linkend="new-in-3.1-environment-abstraction" /> and <xref
linkend="new-in-3.1-property-source-abstraction" />).
<classname>MockEnvironment</classname> and
<classname>MockPropertySource</classname> are useful for developing
<emphasis>out-of-container</emphasis> unit tests for code that depends
on environment-specific properties.</para>
</section>

<section xml:id="mock-objects-jndi">
<title>JNDI</title>

Expand Down

0 comments on commit f49b22c

Please sign in to comment.