Browse Source

Polishing

pull/1915/head
Juergen Hoeller 7 years ago
parent
commit
dc36bb34c7
  1. 28
      spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java
  2. 11
      spring-beans/src/test/java/org/springframework/beans/factory/config/DeprecatedBeanWarnerTests.java

28
spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -19,7 +19,6 @@ package org.springframework.beans.factory.config;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@ -37,21 +36,18 @@ import static org.mockito.BDDMockito.*;
public class CustomScopeConfigurerTests { public class CustomScopeConfigurerTests {
private static final String FOO_SCOPE = "fooScope"; private static final String FOO_SCOPE = "fooScope";
private ConfigurableListableBeanFactory factory;
@Before private final ConfigurableListableBeanFactory factory = new DefaultListableBeanFactory();
public void setUp() {
factory = new DefaultListableBeanFactory();
}
@Test @Test
public void testWithNoScopes() throws Exception { public void testWithNoScopes() {
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.postProcessBeanFactory(factory); figurer.postProcessBeanFactory(factory);
} }
@Test @Test
public void testSunnyDayWithBonaFideScopeInstance() throws Exception { public void testSunnyDayWithBonaFideScopeInstance() {
Scope scope = mock(Scope.class); Scope scope = mock(Scope.class);
factory.registerScope(FOO_SCOPE, scope); factory.registerScope(FOO_SCOPE, scope);
Map<String, Object> scopes = new HashMap<>(); Map<String, Object> scopes = new HashMap<>();
@ -62,7 +58,7 @@ public class CustomScopeConfigurerTests {
} }
@Test @Test
public void testSunnyDayWithBonaFideScopeClass() throws Exception { public void testSunnyDayWithBonaFideScopeClass() {
Map<String, Object> scopes = new HashMap<>(); Map<String, Object> scopes = new HashMap<>();
scopes.put(FOO_SCOPE, NoOpScope.class); scopes.put(FOO_SCOPE, NoOpScope.class);
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
@ -72,7 +68,7 @@ public class CustomScopeConfigurerTests {
} }
@Test @Test
public void testSunnyDayWithBonaFideScopeClassname() throws Exception { public void testSunnyDayWithBonaFideScopeClassName() {
Map<String, Object> scopes = new HashMap<>(); Map<String, Object> scopes = new HashMap<>();
scopes.put(FOO_SCOPE, NoOpScope.class.getName()); scopes.put(FOO_SCOPE, NoOpScope.class.getName());
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
@ -82,7 +78,7 @@ public class CustomScopeConfigurerTests {
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testWhereScopeMapHasNullScopeValueInEntrySet() throws Exception { public void testWhereScopeMapHasNullScopeValueInEntrySet() {
Map<String, Object> scopes = new HashMap<>(); Map<String, Object> scopes = new HashMap<>();
scopes.put(FOO_SCOPE, null); scopes.put(FOO_SCOPE, null);
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
@ -91,9 +87,9 @@ public class CustomScopeConfigurerTests {
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testWhereScopeMapHasNonScopeInstanceInEntrySet() throws Exception { public void testWhereScopeMapHasNonScopeInstanceInEntrySet() {
Map<String, Object> scopes = new HashMap<>(); Map<String, Object> scopes = new HashMap<>();
scopes.put(FOO_SCOPE, this); // <-- not a valid value... scopes.put(FOO_SCOPE, this); // <-- not a valid value...
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.setScopes(scopes); figurer.setScopes(scopes);
figurer.postProcessBeanFactory(factory); figurer.postProcessBeanFactory(factory);
@ -101,9 +97,9 @@ public class CustomScopeConfigurerTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test(expected = ClassCastException.class) @Test(expected = ClassCastException.class)
public void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() throws Exception { public void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() {
Map scopes = new HashMap(); Map scopes = new HashMap();
scopes.put(this, new NoOpScope()); // <-- not a valid value (the key)... scopes.put(this, new NoOpScope()); // <-- not a valid value (the key)...
CustomScopeConfigurer figurer = new CustomScopeConfigurer(); CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.setScopes(scopes); figurer.setScopes(scopes);
figurer.postProcessBeanFactory(factory); figurer.postProcessBeanFactory(factory);

11
spring-beans/src/test/java/org/springframework/beans/factory/config/DeprecatedBeanWarnerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2018 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.
@ -28,28 +28,23 @@ import static org.junit.Assert.*;
*/ */
public class DeprecatedBeanWarnerTests { public class DeprecatedBeanWarnerTests {
private DefaultListableBeanFactory beanFactory;
private String beanName; private String beanName;
private BeanDefinition beanDefinition; private BeanDefinition beanDefinition;
private DeprecatedBeanWarner warner;
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void postProcess() { public void postProcess() {
beanFactory = new DefaultListableBeanFactory(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
BeanDefinition def = new RootBeanDefinition(MyDeprecatedBean.class); BeanDefinition def = new RootBeanDefinition(MyDeprecatedBean.class);
String beanName = "deprecated"; String beanName = "deprecated";
beanFactory.registerBeanDefinition(beanName, def); beanFactory.registerBeanDefinition(beanName, def);
warner = new MyDeprecatedBeanWarner(); DeprecatedBeanWarner warner = new MyDeprecatedBeanWarner();
warner.postProcessBeanFactory(beanFactory); warner.postProcessBeanFactory(beanFactory);
assertEquals(beanName, this.beanName); assertEquals(beanName, this.beanName);
assertEquals(def, this.beanDefinition); assertEquals(def, this.beanDefinition);
} }

Loading…
Cancel
Save