Skip to content

Commit d217855

Browse files
committed
Merge pull request #111 from sbrannen/SPR-9492
Introduce MockEnvironment in the spring-test module
2 parents 0329df2 + f49b22c commit d217855

File tree

9 files changed

+72
-143
lines changed

9 files changed

+72
-143
lines changed

spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,13 +20,14 @@
2020
import org.springframework.core.env.ConfigurableEnvironment;
2121

2222
/**
23-
* Simple {@link ConfigurableEnvironment} implementation exposing a
23+
* Simple {@link ConfigurableEnvironment} implementation exposing
2424
* {@link #setProperty(String, String)} and {@link #withProperty(String, String)}
2525
* methods for testing purposes.
2626
*
2727
* @author Chris Beams
28-
* @since 3.1
29-
* @see MockPropertySource
28+
* @author Sam Brannen
29+
* @since 3.2
30+
* @see org.springframework.mock.env.MockPropertySource
3031
*/
3132
public class MockEnvironment extends AbstractEnvironment {
3233

spring-context/src/test/java/org/springframework/mock/env/MockPropertySource.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@
3636
*
3737
* @author Chris Beams
3838
* @since 3.1
39-
* @see MockEnvironment
39+
* @see org.springframework.mock.env.MockEnvironment
4040
*/
4141
public class MockPropertySource extends PropertiesPropertySource {
4242

@@ -75,7 +75,7 @@ public MockPropertySource(Properties properties) {
7575
}
7676

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

spring-core/src/test/java/org/springframework/mock/env/MockPropertySource.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@
3636
*
3737
* @author Chris Beams
3838
* @since 3.1
39-
* @see MockEnvironment
39+
* @see org.springframework.mock.env.MockEnvironment
4040
*/
4141
public class MockPropertySource extends PropertiesPropertySource {
4242

@@ -75,7 +75,7 @@ public MockPropertySource(Properties properties) {
7575
}
7676

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

spring-expression/src/test/java/org/springframework/mock/env/MockPropertySource.java

-102
This file was deleted.

src/test/java/org/springframework/mock/env/MockEnvironment.java renamed to spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,13 +20,14 @@
2020
import org.springframework.core.env.ConfigurableEnvironment;
2121

2222
/**
23-
* Simple {@link ConfigurableEnvironment} implementation exposing a
23+
* Simple {@link ConfigurableEnvironment} implementation exposing
2424
* {@link #setProperty(String, String)} and {@link #withProperty(String, String)}
2525
* methods for testing purposes.
2626
*
2727
* @author Chris Beams
28-
* @since 3.1
29-
* @see MockPropertySource
28+
* @author Sam Brannen
29+
* @since 3.2
30+
* @see org.springframework.mock.env.MockPropertySource
3031
*/
3132
public class MockEnvironment extends AbstractEnvironment {
3233

spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@
3636
*
3737
* @author Chris Beams
3838
* @since 3.1
39-
* @see MockEnvironment
39+
* @see org.springframework.mock.env.MockEnvironment
4040
*/
4141
public class MockPropertySource extends PropertiesPropertySource {
4242

@@ -75,8 +75,8 @@ public MockPropertySource(Properties properties) {
7575
}
7676

7777
/**
78-
* Create a new {@code MockPropertySource} with with the given name and backed by the given
79-
* {@link Properties} object
78+
* Create a new {@code MockPropertySource} with the given name and backed by the given
79+
* {@link Properties} object.
8080
* @param name the {@linkplain #getName() name} of the property source
8181
* @param properties the properties to use
8282
*/
@@ -100,4 +100,5 @@ public MockPropertySource withProperty(String name, Object value) {
100100
this.setProperty(name, value);
101101
return this;
102102
}
103+
103104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This package contains mock implementations of the
3+
* {@link org.springframework.core.env.Environment Environment} and
4+
* {@link org.springframework.core.env.PropertySource PropertySource}
5+
* abstractions introduced in Spring 3.1.
6+
*
7+
* <p>These <em>mocks</em> are useful for developing <em>out-of-container</em>
8+
* unit tests for code that depends on environment-specific properties.
9+
*/
10+
package org.springframework.mock.env;

src/dist/changelog.txt

+23-23
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ Changes in version 3.2 M2 (2012-08-xx)
77
--------------------------------------
88

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

3434

3535
Changes in version 3.2 M1 (2012-05-28)

src/reference/docbook/testing.xml

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@
4747
<section xml:id="mock-objects">
4848
<title>Mock Objects</title>
4949

50+
<section xml:id="mock-objects-env">
51+
<title>Environment</title>
52+
53+
<para>The <literal>org.springframework.mock.env</literal> package
54+
contains mock implementations of the
55+
<interfacename>Environment</interfacename> and
56+
<interfacename>PropertySource</interfacename> abstractions introduced
57+
in Spring 3.1 (see <xref
58+
linkend="new-in-3.1-environment-abstraction" /> and <xref
59+
linkend="new-in-3.1-property-source-abstraction" />).
60+
<classname>MockEnvironment</classname> and
61+
<classname>MockPropertySource</classname> are useful for developing
62+
<emphasis>out-of-container</emphasis> unit tests for code that depends
63+
on environment-specific properties.</para>
64+
</section>
65+
5066
<section xml:id="mock-objects-jndi">
5167
<title>JNDI</title>
5268

0 commit comments

Comments
 (0)