Browse Source
added <?> wildcard to Scope methods that accept ObjectFactory git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@416 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
13 changed files with 204 additions and 259 deletions
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.beans.factory.config; |
||||
import static org.easymock.EasyMock.*; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
||||
|
||||
/** |
||||
* @author Rick Evans |
||||
* @author Juergen Hoeller |
||||
* @author Chris Beams |
||||
*/ |
||||
public class CustomScopeConfigurerTests { |
||||
|
||||
private static final String FOO_SCOPE = "fooScope"; |
||||
private ConfigurableListableBeanFactory factory; |
||||
|
||||
@Before |
||||
public void setUp() { |
||||
factory = new DefaultListableBeanFactory(); |
||||
} |
||||
|
||||
@Test |
||||
public void testWithNoScopes() throws Exception { |
||||
Scope scope = createMock(Scope.class); |
||||
replay(scope); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.postProcessBeanFactory(factory); |
||||
verify(scope); |
||||
} |
||||
|
||||
@Test |
||||
public void testSunnyDayWithBonaFideScopeInstance() throws Exception { |
||||
Scope scope = createMock(Scope.class); |
||||
replay(scope); |
||||
factory.registerScope(FOO_SCOPE, scope); |
||||
Map<String, Object> scopes = new HashMap<String, Object>(); |
||||
scopes.put(FOO_SCOPE, scope); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
verify(scope); |
||||
} |
||||
|
||||
@Test |
||||
public void testSunnyDayWithBonaFideScopeClass() throws Exception { |
||||
Map<String, Object> scopes = new HashMap<String, Object>(); |
||||
scopes.put(FOO_SCOPE, NoOpScope.class); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope); |
||||
} |
||||
|
||||
@Test |
||||
public void testSunnyDayWithBonaFideScopeClassname() throws Exception { |
||||
Map<String, Object> scopes = new HashMap<String, Object>(); |
||||
scopes.put(FOO_SCOPE, NoOpScope.class.getName()); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope); |
||||
} |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testWhereScopeMapHasNullScopeValueInEntrySet() throws Exception { |
||||
Map<String, Object> scopes = new HashMap<String, Object>(); |
||||
scopes.put(FOO_SCOPE, null); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testWhereScopeMapHasNonScopeInstanceInEntrySet() throws Exception { |
||||
Map<String, Object> scopes = new HashMap<String, Object>(); |
||||
scopes.put(FOO_SCOPE, this); // <-- not a valid value...
|
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
@Test(expected=ClassCastException.class) |
||||
public void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() throws Exception { |
||||
Map scopes = new HashMap(); |
||||
scopes.put(this, new NoOpScope()); // <-- not a valid value (the key)...
|
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
package org.springframework.beans.factory.parsing; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Unit tests for the {@link PropertyEntry} class. |
||||
* |
||||
* @author Rick Evans |
||||
* @author Chris Beams |
||||
*/ |
||||
public final class PropertyEntryTests { |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testCtorBailsOnNullPropertyNameArgument() throws Exception { |
||||
new PropertyEntry(null); |
||||
} |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testCtorBailsOnEmptyPropertyNameArgument() throws Exception { |
||||
new PropertyEntry(""); |
||||
} |
||||
|
||||
@Test(expected=IllegalArgumentException.class) |
||||
public void testCtorBailsOnWhitespacedPropertyNameArgument() throws Exception { |
||||
new PropertyEntry("\t "); |
||||
} |
||||
|
||||
} |
||||
@ -1,155 +0,0 @@
@@ -1,155 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2008 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.beans.factory.config; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.easymock.MockControl; |
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
||||
import org.springframework.mock.easymock.AbstractScalarMockTemplate; |
||||
import org.springframework.test.AssertThrows; |
||||
|
||||
/** |
||||
* @author Rick Evans |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public class CustomScopeConfigurerTests extends TestCase { |
||||
|
||||
private static final String FOO_SCOPE = "fooScope"; |
||||
|
||||
|
||||
public void testWithNoScopes() throws Exception { |
||||
new ConfigurableListableBeanFactoryMockTemplate() { |
||||
protected void doTest(ConfigurableListableBeanFactory factory) { |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testSunnyDayWithBonaFideScopeInstance() throws Exception { |
||||
MockControl mockScope = MockControl.createControl(Scope.class); |
||||
final Scope scope = (Scope) mockScope.getMock(); |
||||
mockScope.replay(); |
||||
new ConfigurableListableBeanFactoryMockTemplate() { |
||||
public void setupExpectations(MockControl mockControl, ConfigurableListableBeanFactory factory) { |
||||
factory.registerScope(FOO_SCOPE, scope); |
||||
} |
||||
protected void doTest(ConfigurableListableBeanFactory factory) { |
||||
Map scopes = new HashMap(); |
||||
scopes.put(FOO_SCOPE, scope); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
}.test(); |
||||
mockScope.verify(); |
||||
} |
||||
|
||||
public void testSunnyDayWithBonaFideScopeClass() throws Exception { |
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
||||
Map scopes = new HashMap(); |
||||
scopes.put(FOO_SCOPE, NoOpScope.class); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope); |
||||
} |
||||
|
||||
public void testSunnyDayWithBonaFideScopeClassname() throws Exception { |
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
||||
Map scopes = new HashMap(); |
||||
scopes.put(FOO_SCOPE, NoOpScope.class.getName()); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope); |
||||
} |
||||
|
||||
public void testWhereScopeMapHasNullScopeValueInEntrySet() throws Exception { |
||||
new ConfigurableListableBeanFactoryMockTemplate() { |
||||
protected void doTest(final ConfigurableListableBeanFactory factory) { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
Map scopes = new HashMap(); |
||||
scopes.put(FOO_SCOPE, null); |
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWhereScopeMapHasNonScopeInstanceInEntrySet() throws Exception { |
||||
new ConfigurableListableBeanFactoryMockTemplate() { |
||||
protected void doTest(final ConfigurableListableBeanFactory factory) { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
Map scopes = new HashMap(); |
||||
scopes.put(FOO_SCOPE, this); // <-- not a valid value...
|
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
public void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() throws Exception { |
||||
new ConfigurableListableBeanFactoryMockTemplate() { |
||||
protected void doTest(final ConfigurableListableBeanFactory factory) { |
||||
new AssertThrows(ClassCastException.class) { |
||||
public void test() throws Exception { |
||||
Map scopes = new HashMap(); |
||||
scopes.put(this, new NoOpScope()); // <-- not a valid value (the key)...
|
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); |
||||
figurer.setScopes(scopes); |
||||
figurer.postProcessBeanFactory(factory); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
}.test(); |
||||
} |
||||
|
||||
|
||||
private abstract class ConfigurableListableBeanFactoryMockTemplate extends AbstractScalarMockTemplate { |
||||
|
||||
public ConfigurableListableBeanFactoryMockTemplate() { |
||||
super(ConfigurableListableBeanFactory.class); |
||||
} |
||||
|
||||
public final void setupExpectations(MockControl mockControl, Object mockObject) throws Exception { |
||||
setupExpectations(mockControl, (ConfigurableListableBeanFactory) mockObject); |
||||
} |
||||
|
||||
public final void doTest(Object mockObject) throws Exception { |
||||
doTest((ConfigurableListableBeanFactory) mockObject); |
||||
} |
||||
|
||||
public void setupExpectations(MockControl mockControl, ConfigurableListableBeanFactory factory) throws Exception { |
||||
} |
||||
|
||||
protected abstract void doTest(ConfigurableListableBeanFactory factory) throws Exception; |
||||
} |
||||
|
||||
} |
||||
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
package org.springframework.beans.factory.parsing; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.springframework.test.AssertThrows; |
||||
|
||||
/** |
||||
* Unit tests for the {@link PropertyEntry} class. |
||||
* |
||||
* @author Rick Evans |
||||
*/ |
||||
public final class PropertyEntryTests extends TestCase { |
||||
|
||||
public void testCtorBailsOnNullPropertyNameArgument() throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
new PropertyEntry(null); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
|
||||
public void testCtorBailsOnEmptyPropertyNameArgument() throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
new PropertyEntry(""); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
|
||||
public void testCtorBailsOnWhitespacedPropertyNameArgument() throws Exception { |
||||
new AssertThrows(IllegalArgumentException.class) { |
||||
public void test() throws Exception { |
||||
new PropertyEntry("\t "); |
||||
} |
||||
}.runTest(); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue