Issue: SPR-9439
This commit is contained in:
Chris Beams 2012-05-26 14:04:36 +03:00
parent 5327a7a37d
commit 5874383ef0
5 changed files with 45 additions and 35 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,13 +55,14 @@ import java.util.Map;
* propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars); * propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
* </pre> * </pre>
* *
* When an {@link Environment} is being used by an ApplicationContext, it is important * When an {@link Environment} is being used by an {@code ApplicationContext}, it is
* that any such PropertySource manipulations be performed <em>before</em> the context's * important that any such {@code PropertySource} manipulations be performed
* {@link org.springframework.context.support.AbstractApplicationContext#refresh() * <em>before</em> the context's {@link
* refresh()} method is called. This ensures that all property sources are available * org.springframework.context.support.AbstractApplicationContext#refresh() refresh()}
* during the container bootstrap process, including use by * method is called. This ensures that all property sources are available during the
* {@linkplain org.springframework.context.support.PropertySourcesPlaceholderConfigurer * container bootstrap process, including use by {@linkplain
* property placeholder configurers}. * org.springframework.context.support.PropertySourcesPlaceholderConfigurer property
* placeholder configurers}.
* *
* *
* @author Chris Beams * @author Chris Beams
@ -78,7 +79,6 @@ public interface ConfigurableEnvironment extends Environment, ConfigurableProper
* <p>Any existing active profiles will be replaced with the given arguments; call * <p>Any existing active profiles will be replaced with the given arguments; call
* with zero arguments to clear the current set of active profiles. Use * with zero arguments to clear the current set of active profiles. Use
* {@link #addActiveProfile} to add a profile while preserving the existing set. * {@link #addActiveProfile} to add a profile while preserving the existing set.
*
* @see #addActiveProfile * @see #addActiveProfile
* @see #setDefaultProfiles * @see #setDefaultProfiles
* @see org.springframework.context.annotation.Profile * @see org.springframework.context.annotation.Profile
@ -123,12 +123,10 @@ public interface ConfigurableEnvironment extends Environment, ConfigurableProper
* Return the value of {@link System#getenv()} if allowed by the current * Return the value of {@link System#getenv()} if allowed by the current
* {@link SecurityManager}, otherwise return a map implementation that will attempt * {@link SecurityManager}, otherwise return a map implementation that will attempt
* to access individual keys using calls to {@link System#getenv(String)}. * to access individual keys using calls to {@link System#getenv(String)}.
*
* <p>Note that most {@link Environment} implementations will include this system * <p>Note that most {@link Environment} implementations will include this system
* environment map as a default {@link PropertySource} to be searched. Therefore, it * environment map as a default {@link PropertySource} to be searched. Therefore, it
* is recommended that this method not be used directly unless bypassing other * is recommended that this method not be used directly unless bypassing other
* property sources is expressly intended. * property sources is expressly intended.
*
* <p>Calls to {@link Map#get(Object)} on the Map returned will never throw * <p>Calls to {@link Map#get(Object)} on the Map returned will never throw
* {@link IllegalAccessException}; in cases where the SecurityManager forbids access * {@link IllegalAccessException}; in cases where the SecurityManager forbids access
* to a property, {@code null} will be returned and an INFO-level log message will be * to a property, {@code null} will be returned and an INFO-level log message will be
@ -140,12 +138,10 @@ public interface ConfigurableEnvironment extends Environment, ConfigurableProper
* Return the value of {@link System#getProperties()} if allowed by the current * Return the value of {@link System#getProperties()} if allowed by the current
* {@link SecurityManager}, otherwise return a map implementation that will attempt * {@link SecurityManager}, otherwise return a map implementation that will attempt
* to access individual keys using calls to {@link System#getProperty(String)}. * to access individual keys using calls to {@link System#getProperty(String)}.
*
* <p>Note that most {@code Environment} implementations will include this system * <p>Note that most {@code Environment} implementations will include this system
* properties map as a default {@link PropertySource} to be searched. Therefore, it is * properties map as a default {@link PropertySource} to be searched. Therefore, it is
* recommended that this method not be used directly unless bypassing other property * recommended that this method not be used directly unless bypassing other property
* sources is expressly intended. * sources is expressly intended.
*
* <p>Calls to {@link Map#get(Object)} on the Map returned will never throw * <p>Calls to {@link Map#get(Object)} on the Map returned will never throw
* {@link IllegalAccessException}; in cases where the SecurityManager forbids access * {@link IllegalAccessException}; in cases where the SecurityManager forbids access
* to a property, {@code null} will be returned and an INFO-level log message will be * to a property, {@code null} will be returned and an INFO-level log message will be

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 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 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
@ -335,7 +335,7 @@ public abstract class Assert {
notNull(type, "Type to check against must not be null"); notNull(type, "Type to check against must not be null");
if (!type.isInstance(obj)) { if (!type.isInstance(obj)) {
throw new IllegalArgumentException(message + throw new IllegalArgumentException(message +
"Object of class [" + (obj != null ? obj.getClass().getName() : "null") + ". Object of class [" + (obj != null ? obj.getClass().getName() : "null") +
"] must be an instance of " + type); "] must be an instance of " + type);
} }
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,22 +16,6 @@
package org.springframework.core.env; package org.springframework.core.env;
import static java.lang.String.format;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.hasItem;
import static org.junit.matchers.JUnitMatchers.hasItems;
import static org.springframework.core.env.AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME;
import static org.springframework.core.env.AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME;
import static org.springframework.core.env.AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.security.Permission; import java.security.Permission;
@ -40,8 +24,18 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.mock.env.MockPropertySource; import org.springframework.mock.env.MockPropertySource;
import static java.lang.String.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.*;
import static org.springframework.core.env.AbstractEnvironment.*;
/** /**
* Unit tests for {@link StandardEnvironment}. * Unit tests for {@link StandardEnvironment}.
* *

View File

@ -1,4 +1,21 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.context; package org.springframework.web.context;
import java.util.Locale; import java.util.Locale;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
@ -136,6 +153,7 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
} }
@SuppressWarnings("serial")
public static class MyEvent extends ApplicationEvent { public static class MyEvent extends ApplicationEvent {
public MyEvent(Object source) { public MyEvent(Object source) {

View File

@ -16,9 +16,6 @@
package org.springframework.web.context; package org.springframework.web.context;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import java.util.Locale; import java.util.Locale;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -36,6 +33,10 @@ import org.springframework.context.TestListener;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.web.context.support.XmlWebApplicationContext;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
@ -53,6 +54,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
beanFactory.addBeanPostProcessor(new BeanPostProcessor() { beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
@SuppressWarnings("unchecked")
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof TestBean) { if (bean instanceof TestBean) {
((TestBean) bean).getFriends().add("myFriend"); ((TestBean) bean).getFriends().add("myFriend");