diff --git a/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java b/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java index a0c220d079..9c9552a298 100644 --- a/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/config/TopLevelAopTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -20,7 +20,6 @@ import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import static org.junit.Assert.*; import static org.springframework.tests.TestResourceUtils.*; @@ -33,13 +32,11 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class TopLevelAopTagTests { - private static final Resource CONTEXT = qualifiedResource(TopLevelAopTagTests.class, "context.xml"); - @Test - public void testParse() throws Exception { + public void testParse() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); - XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); - reader.loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions( + qualifiedResource(TopLevelAopTagTests.class, "context.xml")); assertTrue(beanFactory.containsBeanDefinition("testPointcut")); } diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java index 455778c83e..c5de9deee2 100644 --- a/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/framework/PrototypeTargetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -36,6 +36,7 @@ public class PrototypeTargetTests { private static final Resource CONTEXT = qualifiedResource(PrototypeTargetTests.class, "context.xml"); + @Test public void testPrototypeProxyWithPrototypeTarget() { TestBeanImpl.constructionCount = 0; @@ -64,12 +65,15 @@ public class PrototypeTargetTests { assertEquals(10, interceptor.invocationCount); } - public static interface TestBean { - public void doSomething(); + + public interface TestBean { + + void doSomething(); } public static class TestBeanImpl implements TestBean { + private static int constructionCount = 0; public TestBeanImpl() { @@ -83,6 +87,7 @@ public class PrototypeTargetTests { public static class TestInterceptor implements MethodInterceptor { + private int invocationCount = 0; @Override diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java index 38f0bd9501..4c2735abf2 100644 --- a/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/ExposeInvocationInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -21,7 +21,6 @@ import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.sample.beans.ITestBean; import org.springframework.tests.sample.beans.TestBean; @@ -36,13 +35,11 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class ExposeInvocationInterceptorTests { - private static final Resource CONTEXT = - qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml"); - @Test public void testXmlConfig() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(bf).loadBeanDefinitions( + qualifiedResource(ExposeInvocationInterceptorTests.class, "context.xml")); ITestBean tb = (ITestBean) bf.getBean("proxy"); String name = "tony"; tb.setName(name); @@ -74,6 +71,7 @@ abstract class ExposedInvocationTestBean extends TestBean { class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean { + @Override protected void assertions(MethodInvocation invocation) { assertTrue(invocation.getThis() == this); diff --git a/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java b/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java index 4b5634f2b0..67e1c30ddc 100644 --- a/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyAutowireTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -22,7 +22,6 @@ import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import static org.junit.Assert.*; import static org.springframework.tests.TestResourceUtils.*; @@ -34,16 +33,12 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class ScopedProxyAutowireTests { - private static final Resource SCOPED_AUTOWIRE_FALSE_CONTEXT = - qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml"); - private static final Resource SCOPED_AUTOWIRE_TRUE_CONTEXT = - qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml"); - - @Test public void testScopedProxyInheritsAutowireCandidateFalse() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_FALSE_CONTEXT); + new XmlBeanDefinitionReader(bf).loadBeanDefinitions( + qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml")); + assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped")); assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped")); assertFalse(bf.containsSingleton("scoped")); @@ -55,7 +50,9 @@ public class ScopedProxyAutowireTests { @Test public void testScopedProxyReplacesAutowireCandidateTrue() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_TRUE_CONTEXT); + new XmlBeanDefinitionReader(bf).loadBeanDefinitions( + qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml")); + assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped")); assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped")); assertFalse(bf.containsSingleton("scoped")); diff --git a/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java b/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java index 68b9d26b9c..b1a5b478d5 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/RegexpMethodPointcutAdvisorIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -39,7 +39,8 @@ import static org.springframework.tests.TestResourceUtils.*; public class RegexpMethodPointcutAdvisorIntegrationTests { private static final Resource CONTEXT = - qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml"); + qualifiedResource(RegexpMethodPointcutAdvisorIntegrationTests.class, "context.xml"); + @Test public void testSinglePattern() throws Throwable { diff --git a/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java index 7eb90b8781..051340bed9 100644 --- a/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/target/HotSwappableTargetSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -25,7 +25,6 @@ import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.aop.interceptor.SerializableNopInterceptor; import org.springframework.tests.sample.beans.Person; import org.springframework.tests.sample.beans.SerializablePerson; @@ -41,31 +40,31 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class HotSwappableTargetSourceTests { - private static final Resource CONTEXT = qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml"); - /** Initial count value set in bean factory XML */ private static final int INITIAL_COUNT = 10; private DefaultListableBeanFactory beanFactory; + @Before - public void setUp() throws Exception { + public void setup() { this.beanFactory = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( + qualifiedResource(HotSwappableTargetSourceTests.class, "context.xml")); } /** * We must simulate container shutdown, which should clear threads. */ @After - public void tearDown() { + public void close() { // Will call pool.close() this.beanFactory.destroySingletons(); } + /** * Check it works like a normal invoker - * */ @Test public void testBasicFunctionality() { @@ -106,18 +105,13 @@ public class HotSwappableTargetSourceTests { assertEquals(target1.getCount(), proxied.getCount()); } - - /** - * - * @param invalid - * @return the message - */ - private IllegalArgumentException testRejectsSwapToInvalidValue(Object invalid) { + @Test + public void testRejectsSwapToNull() { HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper"); IllegalArgumentException aopex = null; try { - swapper.swap(invalid); - fail("Shouldn't be able to swap to invalid value [" + invalid + "]"); + swapper.swap(null); + fail("Shouldn't be able to swap to invalid value"); } catch (IllegalArgumentException ex) { // Ok @@ -126,19 +120,9 @@ public class HotSwappableTargetSourceTests { // It shouldn't be corrupted, it should still work testBasicFunctionality(); - return aopex; + assertTrue(aopex.getMessage().contains("null")); } - @Test - public void testRejectsSwapToNull() { - IllegalArgumentException ex = testRejectsSwapToInvalidValue(null); - assertTrue(ex.getMessage().contains("null")); - } - - // TODO test reject swap to wrong interface or class? - // how to decide what's valid? - - @Test public void testSerialization() throws Exception { SerializablePerson sp1 = new SerializablePerson(); @@ -165,4 +149,5 @@ public class HotSwappableTargetSourceTests { assertEquals(sp1.getName(), p.getName()); } + } diff --git a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java index 995ee9f89a..528dce52aa 100644 --- a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeTargetSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -19,11 +19,8 @@ package org.springframework.aop.target; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.sample.beans.SideEffectBean; import static org.junit.Assert.*; @@ -35,19 +32,20 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class PrototypeTargetSourceTests { - private static final Resource CONTEXT = qualifiedResource(PrototypeTargetSourceTests.class, "context.xml"); - /** Initial count value set in bean factory XML */ private static final int INITIAL_COUNT = 10; - private BeanFactory beanFactory; + private DefaultListableBeanFactory beanFactory; + @Before - public void setUp() throws Exception { + public void setup() { this.beanFactory = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( + qualifiedResource(PrototypeTargetSourceTests.class, "context.xml")); } + /** * Test that multiple invocations of the prototype bean will result * in no change to visible state, as a new instance is used. @@ -66,5 +64,4 @@ public class PrototypeTargetSourceTests { assertEquals(INITIAL_COUNT, prototype.getCount()); } - } diff --git a/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java index 0ff97aa8a9..baa6005d0f 100644 --- a/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/target/ThreadLocalTargetSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -21,7 +21,6 @@ import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.sample.beans.ITestBean; import org.springframework.tests.sample.beans.SideEffectBean; @@ -34,26 +33,27 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class ThreadLocalTargetSourceTests { - private static final Resource CONTEXT = qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml"); - /** Initial count value set in bean factory XML */ private static final int INITIAL_COUNT = 10; private DefaultListableBeanFactory beanFactory; + @Before - public void setUp() throws Exception { + public void setup() { this.beanFactory = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( + qualifiedResource(ThreadLocalTargetSourceTests.class, "context.xml")); } /** * We must simulate container shutdown, which should clear threads. */ - protected void tearDown() { + protected void close() { this.beanFactory.destroySingletons(); } + /** * Check we can use two different ThreadLocalTargetSources * managing objects of different types without them interfering @@ -141,7 +141,7 @@ public class ThreadLocalTargetSourceTests { } /** - * Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE + * Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE. */ @Test public void testReuseDestroyedTarget() { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java index c21ab35c9f..a18f0a3266 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/ConcurrentBeanFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -50,10 +50,8 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class ConcurrentBeanFactoryTests { - private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class); - private static final Resource CONTEXT = qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml"); - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd"); + private static final Date DATE_1, DATE_2; static { @@ -66,27 +64,32 @@ public class ConcurrentBeanFactoryTests { } } + + private static final Log logger = LogFactory.getLog(ConcurrentBeanFactoryTests.class); + private BeanFactory factory; - private final Set set = Collections.synchronizedSet(new HashSet()); + private final Set set = Collections.synchronizedSet(new HashSet<>()); + + private Throwable ex; - private Throwable ex = null; @Before - public void setUp() throws Exception { + public void setup() throws Exception { Assume.group(TestGroup.PERFORMANCE); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT); - factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { - @Override - public void registerCustomEditors(PropertyEditorRegistry registry) { - registry.registerCustomEditor(Date.class, new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false)); - } - }); + new XmlBeanDefinitionReader(factory).loadBeanDefinitions( + qualifiedResource(ConcurrentBeanFactoryTests.class, "context.xml")); + + factory.addPropertyEditorRegistrar( + registry -> registry.registerCustomEditor(Date.class, + new CustomDateEditor((DateFormat) DATE_FORMAT.clone(), false))); + this.factory = factory; } + @Test public void testSingleThread() { for (int i = 0; i < 100; i++) { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java index 83dd5af5c5..027975beff 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -21,10 +21,8 @@ import org.junit.Test; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.AutowireCandidateResolver; -import org.springframework.beans.factory.support.BeanDefinitionReader; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import static org.junit.Assert.*; import static org.springframework.tests.TestResourceUtils.*; @@ -38,13 +36,12 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class CustomAutowireConfigurerTests { - private static final Resource CONTEXT = qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml"); - @Test public void testCustomResolver() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); - BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf); - reader.loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(bf).loadBeanDefinitions( + qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml")); + CustomAutowireConfigurer cac = new CustomAutowireConfigurer(); CustomResolver customResolver = new CustomResolver(); bf.setAutowireCandidateResolver(customResolver); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java index 2f432e33be..7c827c5b2a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -22,7 +22,6 @@ import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.sample.beans.TestBean; import static org.junit.Assert.*; @@ -37,9 +36,6 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class FieldRetrievingFactoryBeanTests { - private static final Resource CONTEXT = - qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml"); - @Test public void testStaticField() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); @@ -127,7 +123,9 @@ public class FieldRetrievingFactoryBeanTests { @Test public void testBeanNameSyntaxWithBeanFactory() throws Exception { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(bf).loadBeanDefinitions( + qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml")); + TestBean testBean = (TestBean) bf.getBean("testBean"); assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[0]); assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[1]); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java index 5cc613d8cc..d3535164a7 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2019 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. @@ -27,7 +27,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.util.SerializationTestUtils; import static org.junit.Assert.*; @@ -42,25 +41,25 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class ObjectFactoryCreatingFactoryBeanTests { - private static final Resource CONTEXT = - qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml"); - private DefaultListableBeanFactory beanFactory; + @Before - public void setUp() { + public void setup() { this.beanFactory = new DefaultListableBeanFactory(); - new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( + qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml")); this.beanFactory.setSerializationId("test"); } @After - public void tearDown() { + public void close() { this.beanFactory.setSerializationId(null); } + @Test - public void testFactoryOperation() throws Exception { + public void testFactoryOperation() { FactoryTestBean testBean = beanFactory.getBean("factoryTestBean", FactoryTestBean.class); ObjectFactory objectFactory = testBean.getObjectFactory(); @@ -82,7 +81,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testProviderOperation() throws Exception { + public void testProviderOperation() { ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class); Provider provider = testBean.getProvider(); @@ -152,7 +151,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() throws Exception { + public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() { assertEquals("Must be reporting that it creates ObjectFactory instances (as per class contract).", ObjectFactory.class, new ObjectFactoryCreatingFactoryBean().getObjectType()); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java index 2a81acb06f..dcca770141 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -25,7 +25,6 @@ import org.junit.Test; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.sample.beans.TestBean; import static org.junit.Assert.*; @@ -40,12 +39,11 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class SimpleScopeTests { - private static final Resource CONTEXT = qualifiedResource(SimpleScopeTests.class, "context.xml"); - private DefaultListableBeanFactory beanFactory; + @Before - public void setUp() { + public void setup() { beanFactory = new DefaultListableBeanFactory(); Scope scope = new NoOpScope() { private int index; @@ -69,10 +67,11 @@ public class SimpleScopeTests { assertEquals("myScope", scopeNames[0]); assertSame(scope, beanFactory.getRegisteredScope("myScope")); - XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(beanFactory); - xbdr.loadBeanDefinitions(CONTEXT); + new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions( + qualifiedResource(SimpleScopeTests.class, "context.xml")); } + @Test public void testCanGetScopedObject() { TestBean tb1 = (TestBean) beanFactory.getBean("usesScope"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java index adfe6176cb..7345475d9b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -24,7 +24,6 @@ import org.junit.Test; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.io.Resource; import org.springframework.tests.sample.beans.TestBean; import static org.junit.Assert.*; @@ -37,8 +36,6 @@ import static org.springframework.tests.TestResourceUtils.*; */ public class CustomProblemReporterTests { - private static final Resource CONTEXT = qualifiedResource(CustomProblemReporterTests.class, "context.xml"); - private CollatingProblemReporter problemReporter; private DefaultListableBeanFactory beanFactory; @@ -47,16 +44,17 @@ public class CustomProblemReporterTests { @Before - public void setUp() { + public void setup() { this.problemReporter = new CollatingProblemReporter(); this.beanFactory = new DefaultListableBeanFactory(); this.reader = new XmlBeanDefinitionReader(this.beanFactory); this.reader.setProblemReporter(this.problemReporter); } + @Test public void testErrorsAreCollated() { - this.reader.loadBeanDefinitions(CONTEXT); + this.reader.loadBeanDefinitions(qualifiedResource(CustomProblemReporterTests.class, "context.xml")); assertEquals("Incorrect number of errors collated", 4, this.problemReporter.getErrors().length); TestBean bean = (TestBean) this.beanFactory.getBean("validBean"); diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java index ff3efa860c..bfb5e45004 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -119,7 +119,7 @@ public abstract class Jackson2CodecSupport { @Nullable protected MethodParameter getParameter(ResolvableType type) { - return type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null; + return (type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null); } @Nullable diff --git a/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java index 69a22bbb1a..1e8fba2055 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -39,11 +39,10 @@ import org.springframework.web.context.ServletContextAware; /** * Subclass of {@link GenericApplicationContext}, suitable for web environments. * - *

Implements the - * {@link org.springframework.web.context.ConfigurableWebApplicationContext}, - * but is not intended for declarative setup in {@code web.xml}. Instead, - * it is designed for programmatic setup, for example for building nested contexts or - * for use within Spring 3.1 {@link org.springframework.web.WebApplicationInitializer org.springframework.web.WebApplicationInitializers}. + *

Implements {@link org.springframework.web.context.ConfigurableWebApplicationContext}, + * but is not intended for declarative setup in {@code web.xml}. Instead, it is designed + * for programmatic setup, for example for building nested contexts or for use within + * {@link org.springframework.web.WebApplicationInitializer WebApplicationInitializers}. * *

If you intend to implement a WebApplicationContext that reads bean definitions * from configuration files, consider deriving from AbstractRefreshableWebApplicationContext, diff --git a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java index 0556f2ffc8..a3ac0dea09 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/json/Jackson2JsonDecoderTests.java @@ -42,18 +42,13 @@ import org.springframework.http.MediaType; import org.springframework.http.codec.Pojo; import org.springframework.util.MimeType; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; +import static java.util.Arrays.*; +import static java.util.Collections.*; import static org.junit.Assert.*; -import static org.springframework.core.ResolvableType.forClass; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; -import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON; -import static org.springframework.http.MediaType.APPLICATION_XML; -import static org.springframework.http.codec.json.Jackson2JsonDecoder.JSON_VIEW_HINT; -import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView1; -import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView3; +import static org.springframework.core.ResolvableType.*; +import static org.springframework.http.MediaType.*; +import static org.springframework.http.codec.json.Jackson2JsonDecoder.*; +import static org.springframework.http.codec.json.JacksonViewBean.*; /** * Unit tests for {@link Jackson2JsonDecoder}. @@ -67,10 +62,12 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase { private static final long serialVersionUID = 1L; @@ -254,8 +253,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase