From ab0e6515479f58d2f12b759ee56cc3218f71d2aa Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 20 Jun 2020 18:17:03 +0200 Subject: [PATCH] Polish SerializationTestUtils, clean up warnings, etc. --- ...NamespaceHandlerScopeIntegrationTests.java | 2 +- .../annotation/AspectProxyFactoryTests.java | 9 ++--- .../ConcurrencyThrottleInterceptorTests.java | 4 +-- .../AbstractRegexpMethodPointcutTests.java | 4 +-- ...elegatingIntroductionInterceptorTests.java | 2 +- .../support/NameMatchMethodPointcutTests.java | 4 +-- ...MethodPointcutAdvisorIntegrationTests.java | 4 +-- .../target/HotSwappableTargetSourceTests.java | 4 +-- .../PrototypeBasedTargetSourceTests.java | 4 +-- .../AbstractNestablePropertyAccessor.java | 1 - .../org/springframework/beans/BeanUtils.java | 1 - .../DefaultListableBeanFactoryTests.java | 2 +- ...wiredAnnotationBeanPostProcessorTests.java | 4 +-- ...njectAnnotationBeanPostProcessorTests.java | 14 ++++---- ...ObjectFactoryCreatingFactoryBeanTests.java | 8 ++--- .../aop/framework/AbstractAopProxyTests.java | 4 +-- .../aop/framework/ProxyFactoryBeanTests.java | 6 ++-- .../aop/scope/ScopedProxyTests.java | 4 +-- .../target/CommonsPool2TargetSourceTests.java | 36 +++++++++---------- ...ommonAnnotationBeanPostProcessorTests.java | 18 +++++----- ...mponentScanAnnotationIntegrationTests.java | 4 +-- .../ComponentScanParserScopedProxyTests.java | 6 ++-- .../ApplicationContextExpressionTests.java | 4 +-- .../util/SocketUtilsTests.java | 4 +-- .../io/SerializationTestUtils.java | 23 ++++++++++-- .../AbstractAdaptableMessageListener.java | 7 ++-- .../springframework/jms/StubTextMessage.java | 3 +- .../jms/config/JmsNamespaceHandlerTests.java | 7 ++-- .../SimpleMessageListenerContainerTests.java | 4 ++- .../MessagingMessageListenerAdapterTests.java | 8 ++--- .../jms/remoting/JmsInvokerTests.java | 4 ++- .../MappingJackson2MessageConverterTests.java | 3 +- .../messaging/MessageHeadersTests.java | 4 +-- .../rsocket/DefaultRSocketRequesterTests.java | 4 +-- .../rsocket/RSocketBufferLeakTests.java | 5 ++- ...RSocketServerToClientIntegrationTests.java | 2 +- .../support/MessageHeaderAccessorTests.java | 4 +-- .../support/PersistenceInjectionTests.java | 2 +- ...tationTransactionAttributeSourceTests.java | 2 +- .../config/AnnotationDrivenTests.java | 6 ++-- .../TransactionInterceptorTests.java | 9 +++-- ...aTransactionManagerSerializationTests.java | 5 ++- .../context/request/SessionScopeTests.java | 4 +-- 43 files changed, 133 insertions(+), 126 deletions(-) diff --git a/integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java b/integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java index 32ac556fe48..b4c1131ea1c 100644 --- a/integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java +++ b/integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java @@ -70,7 +70,7 @@ class AopNamespaceHandlerScopeIntegrationTests { assertThat(singletonScoped.getName()).isEqualTo(rob); singletonScoped.setName(bram); assertThat(singletonScoped.getName()).isEqualTo(bram); - ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(singletonScoped); + ITestBean deserialized = SerializationTestUtils.serializeAndDeserialize(singletonScoped); assertThat(deserialized.getName()).isEqualTo(bram); } diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java index d048e6e0d18..30ac2adc43f 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -83,13 +83,12 @@ public class AspectProxyFactoryTests { } @Test - @SuppressWarnings("unchecked") public void testSerializable() throws Exception { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); proxyFactory.addAspect(LoggingAspectOnVarargs.class); ITestBean proxy = proxyFactory.getProxy(); assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue(); - ITestBean tb = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy); + ITestBean tb = SerializationTestUtils.serializeAndDeserialize(proxy); assertThat(tb.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue(); } @@ -108,7 +107,7 @@ public class AspectProxyFactoryTests { ITestBean proxy = proxyFactory.getProxy(); assertThat(proxy.getAge()).isEqualTo((target.getAge() * multiple)); - ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy); + ITestBean serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy); assertThat(serializedProxy.getAge()).isEqualTo((target.getAge() * multiple)); } @@ -120,7 +119,6 @@ public class AspectProxyFactoryTests { } @Test // SPR-13328 - @SuppressWarnings("unchecked") public void testProxiedVarargsWithEnumArray() throws Exception { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); proxyFactory.addAspect(LoggingAspectOnVarargs.class); @@ -129,7 +127,6 @@ public class AspectProxyFactoryTests { } @Test // SPR-13328 - @SuppressWarnings("unchecked") public void testUnproxiedVarargsWithEnumArray() throws Exception { AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean()); proxyFactory.addAspect(LoggingAspectOnSetter.class); diff --git a/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java index 43e4a93ded8..9936573300d 100644 --- a/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -54,7 +54,7 @@ public class ConcurrencyThrottleInterceptorTests { ITestBean proxy = (ITestBean) proxyFactory.getProxy(); proxy.getAge(); - ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy); + ITestBean serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy); Advised advised = (Advised) serializedProxy; ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice(); diff --git a/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java index aa8cd95dc9a..9970b496e2d 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/AbstractRegexpMethodPointcutTests.java @@ -49,7 +49,7 @@ public abstract class AbstractRegexpMethodPointcutTests { @Test public void testSerializationWithNoPatternSupplied() throws Exception { - rpc = (AbstractRegexpMethodPointcut) SerializationTestUtils.serializeAndDeserialize(rpc); + rpc = SerializationTestUtils.serializeAndDeserialize(rpc); noPatternSuppliedTests(rpc); } @@ -63,7 +63,7 @@ public abstract class AbstractRegexpMethodPointcutTests { public void testExactMatch() throws Exception { rpc.setPattern("java.lang.Object.hashCode"); exactMatchTests(rpc); - rpc = (AbstractRegexpMethodPointcut) SerializationTestUtils.serializeAndDeserialize(rpc); + rpc = SerializationTestUtils.serializeAndDeserialize(rpc); exactMatchTests(rpc); } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java b/spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java index 4325e582704..3e6e08afc1c 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/DelegatingIntroductionInterceptorTests.java @@ -239,7 +239,7 @@ public class DelegatingIntroductionInterceptorTests { assertThat(p.getName()).isEqualTo(name); assertThat(((TimeStamped) p).getTimeStamp()).isEqualTo(time); - Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p); + Person p1 = SerializationTestUtils.serializeAndDeserialize(p); assertThat(p1.getName()).isEqualTo(name); assertThat(((TimeStamped) p1).getTimeStamp()).isEqualTo(time); } diff --git a/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java index 98f7ca29a97..6c7928a83e6 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -109,7 +109,7 @@ public class NameMatchMethodPointcutTests { public void testSerializable() throws Throwable { testSets(); // Count is now 2 - Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(proxied); + Person p2 = SerializationTestUtils.serializeAndDeserialize(proxied); NopInterceptor nop2 = (NopInterceptor) ((Advised) p2).getAdvisors()[0].getAdvice(); p2.getName(); assertThat(nop2.getCount()).isEqualTo(2); 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 de3886ef85e..c3b546c3604 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-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -109,7 +109,7 @@ public class RegexpMethodPointcutAdvisorIntegrationTests { assertThat(nop.getCount()).isEqualTo(2); // Serialize and continue... - p = (Person) SerializationTestUtils.serializeAndDeserialize(p); + p = SerializationTestUtils.serializeAndDeserialize(p); assertThat(p.getAge()).isEqualTo(newAge); // Remembers count, but we need to get a new reference to nop... nop = (SerializableNopInterceptor) ((Advised) p).getAdvisors()[0].getAdvice(); 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 a3354a5587f..a396adafdcd 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-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -134,7 +134,7 @@ public class HotSwappableTargetSourceTests { hts.swap(sp2); assertThat(p.getName()).isEqualTo(sp2.getName()); - p = (Person) SerializationTestUtils.serializeAndDeserialize(p); + p = SerializationTestUtils.serializeAndDeserialize(p); // We need to get a reference to the client-side targetsource hts = (HotSwappableTargetSource) ((Advised) p).getTargetSource(); assertThat(p.getName()).isEqualTo(sp2.getName()); diff --git a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java index 3a84193d50f..24af32140c7 100644 --- a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -55,7 +55,7 @@ public class PrototypeBasedTargetSourceTests { bf.registerBeanDefinition("person", bd); TestTargetSource cpts = (TestTargetSource) bf.getBean("ts"); - TargetSource serialized = (TargetSource) SerializationTestUtils.serializeAndDeserialize(cpts); + TargetSource serialized = SerializationTestUtils.serializeAndDeserialize(cpts); boolean condition = serialized instanceof SingletonTargetSource; assertThat(condition).as("Changed to SingletonTargetSource on deserialization").isTrue(); SingletonTargetSource sts = (SingletonTargetSource) serialized; diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java index 74665196819..cd910621fbe 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java @@ -806,7 +806,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA * @param propertyPath property path, which may be nested * @return a property accessor for the target bean */ - @SuppressWarnings("unchecked") // avoid nested generic protected AbstractNestablePropertyAccessor getPropertyAccessorForPropertyPath(String propertyPath) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath); // Handle nested properties recursively. diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java index 99cb076903f..e467866c534 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -228,7 +228,6 @@ public abstract class BeanUtils { * @since 5.0 * @see Kotlin docs */ - @SuppressWarnings("unchecked") @Nullable public static Constructor findPrimaryConstructor(Class clazz) { Assert.notNull(clazz, "Class must not be null"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index 63c53612290..56bb5511569 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -1787,7 +1787,7 @@ class DefaultListableBeanFactoryTests { lbf.setSerializationId("test"); ObjectProvider provider = lbf.getBeanProvider(ConstructorDependency.class); - ObjectProvider deserialized = (ObjectProvider) SerializationTestUtils.serializeAndDeserialize(provider); + ObjectProvider deserialized = SerializationTestUtils.serializeAndDeserialize(provider); assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy( deserialized::getObject); assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java index 69829b2eb2a..39a8d4b0afe 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -1135,7 +1135,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { ObjectFactoryFieldInjectionBean bean = (ObjectFactoryFieldInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java index 43e57e7d26a..aa4c1cb20bf 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -394,7 +394,7 @@ public class InjectAnnotationBeanPostProcessorTests { ObjectFactoryFieldInjectionBean bean = (ObjectFactoryFieldInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } @@ -406,7 +406,7 @@ public class InjectAnnotationBeanPostProcessorTests { ObjectFactoryMethodInjectionBean bean = (ObjectFactoryMethodInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } @@ -418,7 +418,7 @@ public class InjectAnnotationBeanPostProcessorTests { ObjectFactoryListFieldInjectionBean bean = (ObjectFactoryListFieldInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryListFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } @@ -430,7 +430,7 @@ public class InjectAnnotationBeanPostProcessorTests { ObjectFactoryListMethodInjectionBean bean = (ObjectFactoryListMethodInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryListMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } @@ -442,7 +442,7 @@ public class InjectAnnotationBeanPostProcessorTests { ObjectFactoryMapFieldInjectionBean bean = (ObjectFactoryMapFieldInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryMapFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } @@ -454,7 +454,7 @@ public class InjectAnnotationBeanPostProcessorTests { ObjectFactoryMapMethodInjectionBean bean = (ObjectFactoryMapMethodInjectionBean) bf.getBean("annotatedBean"); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); - bean = (ObjectFactoryMapMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean); + bean = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean")); } 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 97805143da8..7357ba9069d 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-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -72,12 +72,11 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - @SuppressWarnings("rawtypes") public void testFactorySerialization() throws Exception { FactoryTestBean testBean = beanFactory.getBean("factoryTestBean", FactoryTestBean.class); ObjectFactory objectFactory = testBean.getObjectFactory(); - objectFactory = (ObjectFactory) SerializationTestUtils.serializeAndDeserialize(objectFactory); + objectFactory = SerializationTestUtils.serializeAndDeserialize(objectFactory); Date date1 = (Date) objectFactory.getObject(); Date date2 = (Date) objectFactory.getObject(); @@ -95,12 +94,11 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - @SuppressWarnings("rawtypes") public void testProviderSerialization() throws Exception { ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class); Provider provider = testBean.getProvider(); - provider = (Provider) SerializationTestUtils.serializeAndDeserialize(provider); + provider = SerializationTestUtils.serializeAndDeserialize(provider); Date date1 = (Date) provider.get(); Date date2 = (Date) provider.get(); diff --git a/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java index e27dbfcacb9..fb5914f3b3b 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -246,7 +246,7 @@ public abstract class AbstractAopProxyTests { assertThat(cta.getCalls()).isEqualTo(1); // Will throw exception if it fails - Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); + Person p2 = SerializationTestUtils.serializeAndDeserialize(p); assertThat(p2).isNotSameAs(p); assertThat(p2.getName()).isEqualTo(p.getName()); assertThat(p2.getAge()).isEqualTo(p.getAge()); diff --git a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java index 021a8a70eee..bca9e855738 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java @@ -523,7 +523,7 @@ public class ProxyFactoryBeanTests { new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("serializableSingleton"); assertThat(bf.getBean("serializableSingleton")).as("Should be a Singleton").isSameAs(p); - Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); + Person p2 = SerializationTestUtils.serializeAndDeserialize(p); assertThat(p2).isEqualTo(p); assertThat(p2).isNotSameAs(p); assertThat(p2.getName()).isEqualTo("serializableSingleton"); @@ -546,7 +546,7 @@ public class ProxyFactoryBeanTests { new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("serializablePrototype"); assertThat(bf.getBean("serializablePrototype")).as("Should not be a Singleton").isNotSameAs(p); - Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); + Person p2 = SerializationTestUtils.serializeAndDeserialize(p); assertThat(p2).isEqualTo(p); assertThat(p2).isNotSameAs(p); assertThat(p2.getName()).isEqualTo("serializablePrototype"); @@ -558,7 +558,7 @@ public class ProxyFactoryBeanTests { new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); Person p = (Person) bf.getBean("serializableSingleton"); ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton"); - ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb); + ProxyFactoryBean pfb2 = SerializationTestUtils.serializeAndDeserialize(pfb); Person p2 = (Person) pfb2.getObject(); assertThat(p2).isEqualTo(p); assertThat(p2).isNotSameAs(p); diff --git a/spring-context/src/test/java/org/springframework/aop/scope/ScopedProxyTests.java b/spring-context/src/test/java/org/springframework/aop/scope/ScopedProxyTests.java index 7ef136b9827..1f215849aa0 100644 --- a/spring-context/src/test/java/org/springframework/aop/scope/ScopedProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/scope/ScopedProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -106,7 +106,7 @@ public class ScopedProxyTests { assertThat(scope.getMap().containsKey("testBeanTarget")).isTrue(); assertThat(scope.getMap().get("testBeanTarget").getClass()).isEqualTo(TestBean.class); - ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(bean); + ITestBean deserialized = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(deserialized).isNotNull(); assertThat(AopUtils.isJdkDynamicProxy(deserialized)).isTrue(); assertThat(bean.getAge()).isEqualTo(101); diff --git a/spring-context/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceTests.java b/spring-context/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceTests.java index ebfc29c8fd5..0cf766f253e 100644 --- a/spring-context/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceTests.java +++ b/spring-context/src/test/java/org/springframework/aop/target/CommonsPool2TargetSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Tests for pooling invoker interceptor. + * * TODO: need to make these tests stronger: it's hard to * make too many assumptions about a pool. * @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Chris Beams * @author Stephane Nicoll */ -public class CommonsPool2TargetSourceTests { +class CommonsPool2TargetSourceTests { /** * Initial count value set in bean factory XML @@ -55,7 +56,7 @@ public class CommonsPool2TargetSourceTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { this.beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); @@ -65,7 +66,7 @@ public class CommonsPool2TargetSourceTests { * We must simulate container shutdown, which should clear threads. */ @AfterEach - public void tearDown() { + void tearDown() { // Will call pool.close() this.beanFactory.destroySingletons(); } @@ -84,17 +85,17 @@ public class CommonsPool2TargetSourceTests { } @Test - public void testFunctionality() { + void testFunctionality() { testFunctionality("pooled"); } @Test - public void testFunctionalityWithNoInterceptors() { + void testFunctionalityWithNoInterceptors() { testFunctionality("pooledNoInterceptors"); } @Test - public void testConfigMixin() { + void testConfigMixin() { SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin"); assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT); PoolingConfig conf = (PoolingConfig) beanFactory.getBean("pooledWithMixin"); @@ -109,25 +110,22 @@ public class CommonsPool2TargetSourceTests { } @Test - public void testTargetSourceSerializableWithoutConfigMixin() throws Exception { + void testTargetSourceSerializableWithoutConfigMixin() throws Exception { CommonsPool2TargetSource cpts = (CommonsPool2TargetSource) beanFactory.getBean("personPoolTargetSource"); - SingletonTargetSource serialized = (SingletonTargetSource) SerializationTestUtils.serializeAndDeserialize(cpts); - boolean condition = serialized.getTarget() instanceof Person; - assertThat(condition).isTrue(); + SingletonTargetSource serialized = SerializationTestUtils.serializeAndDeserialize(cpts, SingletonTargetSource.class); + assertThat(serialized.getTarget()).isInstanceOf(Person.class); } - @Test - public void testProxySerializableWithoutConfigMixin() throws Exception { + void testProxySerializableWithoutConfigMixin() throws Exception { Person pooled = (Person) beanFactory.getBean("pooledPerson"); - //System.out.println(((Advised) pooled).toProxyConfigString()); boolean condition1 = ((Advised) pooled).getTargetSource() instanceof CommonsPool2TargetSource; assertThat(condition1).isTrue(); //((Advised) pooled).setTargetSource(new SingletonTargetSource(new SerializablePerson())); - Person serialized = (Person) SerializationTestUtils.serializeAndDeserialize(pooled); + Person serialized = SerializationTestUtils.serializeAndDeserialize(pooled); boolean condition = ((Advised) serialized).getTargetSource() instanceof SingletonTargetSource; assertThat(condition).isTrue(); serialized.setAge(25); @@ -135,7 +133,7 @@ public class CommonsPool2TargetSourceTests { } @Test - public void testHitMaxSize() throws Exception { + void testHitMaxSize() throws Exception { int maxSize = 10; CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource(); @@ -166,7 +164,7 @@ public class CommonsPool2TargetSourceTests { } @Test - public void testHitMaxSizeLoadedFromContext() throws Exception { + void testHitMaxSizeLoadedFromContext() throws Exception { Advised person = (Advised) beanFactory.getBean("maxSizePooledPerson"); CommonsPool2TargetSource targetSource = (CommonsPool2TargetSource) person.getTargetSource(); @@ -195,14 +193,14 @@ public class CommonsPool2TargetSourceTests { } @Test - public void testSetWhenExhaustedAction() { + void testSetWhenExhaustedAction() { CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource(); targetSource.setBlockWhenExhausted(true); assertThat(targetSource.isBlockWhenExhausted()).isEqualTo(true); } @Test - public void referenceIdentityByDefault() throws Exception { + void referenceIdentityByDefault() throws Exception { CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource(); targetSource.setMaxWait(1); prepareTargetSource(targetSource); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java index 631ca5644f9..3d300b71dbe 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -33,7 +33,6 @@ import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.INestedTestBean; @@ -122,8 +121,7 @@ public class CommonAnnotationBeanPostProcessorTests { @Test public void testSerialization() throws Exception { CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); - CommonAnnotationBeanPostProcessor bpp2 = (CommonAnnotationBeanPostProcessor) - SerializationTestUtils.serializeAndDeserialize(bpp); + CommonAnnotationBeanPostProcessor bpp2 = SerializationTestUtils.serializeAndDeserialize(bpp); AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean(); bpp2.postProcessBeforeDestruction(bean, "annotatedBean"); @@ -135,8 +133,7 @@ public class CommonAnnotationBeanPostProcessorTests { InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor(); bpp.setInitAnnotationType(PostConstruct.class); bpp.setDestroyAnnotationType(PreDestroy.class); - InitDestroyAnnotationBeanPostProcessor bpp2 = (InitDestroyAnnotationBeanPostProcessor) - SerializationTestUtils.serializeAndDeserialize(bpp); + InitDestroyAnnotationBeanPostProcessor bpp2 = SerializationTestUtils.serializeAndDeserialize(bpp); AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean(); bpp2.postProcessBeforeDestruction(bean, "annotatedBean"); @@ -225,7 +222,8 @@ public class CommonAnnotationBeanPostProcessorTests { } }); - PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); + @SuppressWarnings("deprecation") + org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean4"); ppc.setProperties(props); @@ -322,7 +320,8 @@ public class CommonAnnotationBeanPostProcessorTests { bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); - PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); + @SuppressWarnings("deprecation") + org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); ppc.setProperties(props); @@ -374,7 +373,8 @@ public class CommonAnnotationBeanPostProcessorTests { bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); - PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); + @SuppressWarnings("deprecation") + org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); ppc.setProperties(props); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java index 9e203c4b631..17e13829c2d 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -212,7 +212,7 @@ public class ComponentScanAnnotationIntegrationTests { assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue(); // test serializability assertThat(bean.foo(1)).isEqualTo("bar"); - FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean); + FooService deserialized = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(deserialized).isNotNull(); assertThat(deserialized.foo(1)).isEqualTo("bar"); } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java index cea9f6af5d1..e498e947035 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -72,7 +72,7 @@ public class ComponentScanParserScopedProxyTests { assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue(); // test serializability assertThat(bean.foo(1)).isEqualTo("bar"); - FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean); + FooService deserialized = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(deserialized).isNotNull(); assertThat(deserialized.foo(1)).isEqualTo("bar"); context.close(); @@ -89,7 +89,7 @@ public class ComponentScanParserScopedProxyTests { assertThat(AopUtils.isCglibProxy(bean)).isTrue(); // test serializability assertThat(bean.foo(1)).isEqualTo("bar"); - ScopedProxyTestBean deserialized = (ScopedProxyTestBean) SerializationTestUtils.serializeAndDeserialize(bean); + ScopedProxyTestBean deserialized = SerializationTestUtils.serializeAndDeserialize(bean); assertThat(deserialized).isNotNull(); assertThat(deserialized.foo(1)).isEqualTo("bar"); context.close(); diff --git a/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java b/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java index 274be7aef12..905cf736726 100644 --- a/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java +++ b/spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -186,7 +186,7 @@ class ApplicationContextExpressionTests { assertThat(tb3.optionalValue3.isPresent()).isFalse(); assertThat(tb3.tb).isSameAs(tb0); - tb3 = (ValueTestBean) SerializationTestUtils.serializeAndDeserialize(tb3); + tb3 = SerializationTestUtils.serializeAndDeserialize(tb3); assertThat(tb3.countryFactory.getObject()).isEqualTo("123 UK"); ConstructorValueTestBean tb4 = ac.getBean("tb4", ConstructorValueTestBean.class); diff --git a/spring-core/src/test/java/org/springframework/util/SocketUtilsTests.java b/spring-core/src/test/java/org/springframework/util/SocketUtilsTests.java index 0f62fedb539..d13e78e6c61 100644 --- a/spring-core/src/test/java/org/springframework/util/SocketUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/SocketUtilsTests.java @@ -75,10 +75,10 @@ class SocketUtilsTests { } @Test - @SuppressWarnings("try") void findAvailableTcpPortWhenPortOnLoopbackInterfaceIsNotAvailable() throws Exception { int port = SocketUtils.findAvailableTcpPort(); try (ServerSocket socket = ServerSocketFactory.getDefault().createServerSocket(port, 1, InetAddress.getByName("localhost"))) { + assertThat(socket).isNotNull(); // will only look for the exact port assertThatIllegalStateException().isThrownBy(() -> SocketUtils.findAvailableTcpPort(port, port)) @@ -149,10 +149,10 @@ class SocketUtilsTests { } @Test - @SuppressWarnings("try") void findAvailableUdpPortWhenPortOnLoopbackInterfaceIsNotAvailable() throws Exception { int port = SocketUtils.findAvailableUdpPort(); try (DatagramSocket socket = new DatagramSocket(port, InetAddress.getByName("localhost"))) { + assertThat(socket).isNotNull(); // will only look for the exact port assertThatIllegalStateException().isThrownBy(() -> SocketUtils.findAvailableUdpPort(port, port)) diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/SerializationTestUtils.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/SerializationTestUtils.java index ebeec7bf6a3..4c5b8842ea9 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/SerializationTestUtils.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/SerializationTestUtils.java @@ -26,9 +26,11 @@ import java.io.OutputStream; /** * Utilities for testing serializability of objects. - * Exposes static methods for use in other test cases. + * + *

Exposes static methods for use in other test cases. * * @author Rod Johnson + * @author Sam Brannen */ public class SerializationTestUtils { @@ -49,7 +51,22 @@ public class SerializationTestUtils { } } - public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException { + @SuppressWarnings("unchecked") + public static T serializeAndDeserialize(T o) throws IOException, ClassNotFoundException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(o); + oos.flush(); + } + byte[] bytes = baos.toByteArray(); + + ByteArrayInputStream is = new ByteArrayInputStream(bytes); + try (ObjectInputStream ois = new ObjectInputStream(is)) { + return (T) ois.readObject(); + } + } + + public static T serializeAndDeserialize(Object o, Class expectedType) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(o); @@ -59,7 +76,7 @@ public class SerializationTestUtils { ByteArrayInputStream is = new ByteArrayInputStream(bytes); try (ObjectInputStream ois = new ObjectInputStream(is)) { - return ois.readObject(); + return expectedType.cast(ois.readObject()); } } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java index 9c1a3ca325c..e4b9cd44261 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -459,13 +459,12 @@ public abstract class AbstractAdaptableMessageListener /** - * A {@link MessagingMessageConverter} that lazily invoke payload extraction and - * delegate it to {@link #extractMessage(javax.jms.Message)} in order to enforce + * A {@link MessagingMessageConverter} that lazily invokes payload extraction and + * delegates it to {@link #extractMessage(javax.jms.Message)} in order to enforce * backward compatibility. */ private class MessagingMessageConverterAdapter extends MessagingMessageConverter { - @SuppressWarnings("unchecked") @Override public Object fromMessage(javax.jms.Message message) throws JMSException, MessageConversionException { return new LazyResolutionMessage(message); diff --git a/spring-jms/src/test/java/org/springframework/jms/StubTextMessage.java b/spring-jms/src/test/java/org/springframework/jms/StubTextMessage.java index 1c28c2615d3..cb4d0ee6f12 100644 --- a/spring-jms/src/test/java/org/springframework/jms/StubTextMessage.java +++ b/spring-jms/src/test/java/org/springframework/jms/StubTextMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 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. @@ -325,6 +325,7 @@ public class StubTextMessage implements TextMessage { } @Override + @SuppressWarnings("rawtypes") public boolean isBodyAssignableTo(Class c) throws JMSException { return false; } diff --git a/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java b/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java index ec5d566222f..8755e944b2e 100644 --- a/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -87,9 +87,8 @@ public class JmsNamespaceHandlerTests { containers = context.getBeansOfType(GenericMessageEndpointManager.class); assertThat(containers.size()).as("Context should contain 3 JCA endpoint containers").isEqualTo(3); - Map containerFactories = - context.getBeansOfType(JmsListenerContainerFactory.class); - assertThat(containerFactories.size()).as("Context should contain 3 JmsListenerContainerFactory instances").isEqualTo(3); + assertThat(context.getBeansOfType(JmsListenerContainerFactory.class)) + .as("Context should contain 3 JmsListenerContainerFactory instances").hasSize(3); } @Test diff --git a/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java b/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java index 6f8ca80c4fe..ae9e9c64fb3 100644 --- a/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -121,6 +121,7 @@ public class SimpleMessageListenerContainerTests { GenericApplicationContext context = new GenericApplicationContext(); context.getBeanFactory().registerSingleton("messageListenerContainer", this.container); context.refresh(); + context.close(); verify(connection).setExceptionListener(this.container); } @@ -151,6 +152,7 @@ public class SimpleMessageListenerContainerTests { GenericApplicationContext context = new GenericApplicationContext(); context.getBeanFactory().registerSingleton("messageListenerContainer", this.container); context.refresh(); + context.close(); verify(connection).setExceptionListener(this.container); verify(connection).start(); diff --git a/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java b/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java index 4d0011efffc..4a984a256e3 100644 --- a/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapterTests.java @@ -341,7 +341,7 @@ public class MessagingMessageListenerAdapterTests { } - protected MessagingMessageListenerAdapter getSimpleInstance(String methodName, Class... parameterTypes) { + protected MessagingMessageListenerAdapter getSimpleInstance(String methodName, Class... parameterTypes) { Method m = ReflectionUtils.findMethod(SampleBean.class, methodName, parameterTypes); return createInstance(m); } @@ -353,7 +353,7 @@ public class MessagingMessageListenerAdapterTests { } protected MessagingMessageListenerAdapter getPayloadInstance(final Object payload, - String methodName, Class... parameterTypes) { + String methodName, Class... parameterTypes) { Method method = ReflectionUtils.findMethod(SampleBean.class, methodName, parameterTypes); MessagingMessageListenerAdapter adapter = new MessagingMessageListenerAdapter() { @@ -435,6 +435,7 @@ public class MessagingMessageListenerAdapterTests { interface Summary {}; interface Full extends Summary {}; + @SuppressWarnings("unused") private static class SampleResponse { private int counter = 42; @@ -445,9 +446,6 @@ public class MessagingMessageListenerAdapterTests { @JsonView(Full.class) private String description; - SampleResponse() { - } - public SampleResponse(String name, String description) { this.name = name; this.description = description; diff --git a/spring-jms/src/test/java/org/springframework/jms/remoting/JmsInvokerTests.java b/spring-jms/src/test/java/org/springframework/jms/remoting/JmsInvokerTests.java index 49ce0eeb6b9..63354c358a1 100644 --- a/spring-jms/src/test/java/org/springframework/jms/remoting/JmsInvokerTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/remoting/JmsInvokerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -392,6 +392,7 @@ public class JmsInvokerTests { } @Override + @SuppressWarnings("rawtypes") public boolean isBodyAssignableTo(Class c) throws JMSException { return false; } @@ -451,6 +452,7 @@ public class JmsInvokerTests { } @Override + @SuppressWarnings("rawtypes") public Enumeration getPropertyNames() throws JMSException { return null; } diff --git a/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java b/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java index bbaa4f05c35..a7942cccb8e 100644 --- a/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -311,6 +311,7 @@ public class MappingJackson2MessageConverterTests { private interface Full extends Summary {}; + @SuppressWarnings("unused") private static class MyAnotherBean { @JsonView(Summary.class) diff --git a/spring-messaging/src/test/java/org/springframework/messaging/MessageHeadersTests.java b/spring-messaging/src/test/java/org/springframework/messaging/MessageHeadersTests.java index 06f18f9000a..5504cd811be 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/MessageHeadersTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/MessageHeadersTests.java @@ -164,7 +164,7 @@ public class MessageHeadersTests { map.put("name", "joe"); map.put("age", 42); MessageHeaders input = new MessageHeaders(map); - MessageHeaders output = (MessageHeaders) SerializationTestUtils.serializeAndDeserialize(input); + MessageHeaders output = SerializationTestUtils.serializeAndDeserialize(input); assertThat(output.get("name")).isEqualTo("joe"); assertThat(output.get("age")).isEqualTo(42); assertThat(input.get("name")).isEqualTo("joe"); @@ -178,7 +178,7 @@ public class MessageHeadersTests { map.put("name", "joe"); map.put("address", address); MessageHeaders input = new MessageHeaders(map); - MessageHeaders output = (MessageHeaders) SerializationTestUtils.serializeAndDeserialize(input); + MessageHeaders output = SerializationTestUtils.serializeAndDeserialize(input); assertThat(output.get("name")).isEqualTo("joe"); assertThat(output.get("address")).isNull(); assertThat(input.get("name")).isEqualTo("joe"); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterTests.java index 54ee6c56ae1..76649d178b2 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterTests.java @@ -27,8 +27,8 @@ import java.util.function.Function; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; -import io.rsocket.AbstractRSocket; import io.rsocket.Payload; +import io.rsocket.RSocket; import io.rsocket.metadata.WellKnownMimeType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -248,7 +248,7 @@ public class DefaultRSocketRequesterTests { } - private static class TestRSocket extends AbstractRSocket { + private static class TestRSocket implements RSocket { private Mono payloadMonoToReturn = Mono.empty(); private Flux payloadFluxToReturn = Flux.empty(); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketBufferLeakTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketBufferLeakTests.java index 89ef3f119df..1906ba00b61 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketBufferLeakTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketBufferLeakTests.java @@ -23,7 +23,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import io.netty.buffer.PooledByteBufAllocator; import io.netty.util.ReferenceCounted; -import io.rsocket.AbstractRSocket; import io.rsocket.RSocket; import io.rsocket.SocketAcceptor; import io.rsocket.core.RSocketServer; @@ -240,7 +239,7 @@ class RSocketBufferLeakTests { * Store all intercepted incoming and outgoing payloads and then use * {@link #checkForLeaks()} at the end to check reference counts. */ - private static class PayloadInterceptor extends AbstractRSocket implements RSocketInterceptor { + private static class PayloadInterceptor implements RSocket, RSocketInterceptor { private final List rsockets = new CopyOnWriteArrayList<>(); @@ -288,7 +287,7 @@ class RSocketBufferLeakTests { } - private static class PayloadSavingDecorator extends AbstractRSocket { + private static class PayloadSavingDecorator implements RSocket { private final RSocket delegate; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketServerToClientIntegrationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketServerToClientIntegrationTests.java index b651c19db58..c74058573a5 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketServerToClientIntegrationTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/RSocketServerToClientIntegrationTests.java @@ -204,7 +204,7 @@ public class RSocketServerToClientIntegrationTests { Mono.fromRunnable(testEcho) .doOnError(ex -> result.onError(ex)) .doOnSuccess(o -> result.onComplete()) - .subscribeOn(Schedulers.elastic()) // StepVerifier will block + .subscribeOn(Schedulers.boundedElastic()) // StepVerifier will block .subscribe(); } } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/support/MessageHeaderAccessorTests.java b/spring-messaging/src/test/java/org/springframework/messaging/support/MessageHeaderAccessorTests.java index 937bdaef4c4..ff7c4cee82e 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/support/MessageHeaderAccessorTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/support/MessageHeaderAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -384,7 +384,7 @@ public class MessageHeaderAccessorTests { mutableAccessor.setContentType(MimeTypeUtils.TEXT_PLAIN); message = new GenericMessage<>(message.getPayload(), mutableAccessor.getMessageHeaders()); - Message output = (Message) SerializationTestUtils.serializeAndDeserialize(message); + Message output = SerializationTestUtils.serializeAndDeserialize(message); assertThat(output.getPayload()).isEqualTo("test"); assertThat(output.getHeaders().get("foo")).isEqualTo("bar"); assertThat(output.getHeaders().get(MessageHeaders.CONTENT_TYPE)).isNotNull(); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java index 61d04f1a94c..919f2fb1259 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java @@ -187,7 +187,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT assertThat(bean.em).isNotNull(); assertThat(SerializationTestUtils.serializeAndDeserialize(bean.em)).isNotNull(); - SimpleMapScope serialized = (SimpleMapScope) SerializationTestUtils.serializeAndDeserialize(myScope); + SimpleMapScope serialized = SerializationTestUtils.serializeAndDeserialize(myScope); serialized.close(); assertThat(DummyInvocationHandler.closed).isTrue(); DummyInvocationHandler.closed = false; diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java index dde5bd1dbf9..d94dc4bf495 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java @@ -65,7 +65,7 @@ public class AnnotationTransactionAttributeSourceTests { proxy.getAge(); assertThat(ptm.commits).isEqualTo(1); - ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy); + ITestBean1 serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy); serializedProxy.getAge(); Advised advised = (Advised) serializedProxy; TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice(); diff --git a/spring-tx/src/test/java/org/springframework/transaction/config/AnnotationDrivenTests.java b/spring-tx/src/test/java/org/springframework/transaction/config/AnnotationDrivenTests.java index 2d19c185e57..5fda90664f5 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/config/AnnotationDrivenTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/config/AnnotationDrivenTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -87,7 +87,7 @@ public class AnnotationDrivenTests { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass()); TransactionalService service = context.getBean("service", TransactionalService.class); service.setSomething("someName"); - service = (TransactionalService) SerializationTestUtils.serializeAndDeserialize(service); + service = SerializationTestUtils.serializeAndDeserialize(service); service.setSomething("someName"); } @@ -96,7 +96,7 @@ public class AnnotationDrivenTests { public void serializableWithoutPreviousUsage() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass()); TransactionalService service = context.getBean("service", TransactionalService.class); - service = (TransactionalService) SerializationTestUtils.serializeAndDeserialize(service); + service = SerializationTestUtils.serializeAndDeserialize(service); service.setSomething("someName"); } diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java index c870022cc2f..79b74fd1ae5 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -90,12 +90,11 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests ti.setTransactionAttributes(props); PlatformTransactionManager ptm = new SerializableTransactionManager(); ti.setTransactionManager(ptm); - ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); + ti = SerializationTestUtils.serializeAndDeserialize(ti); // Check that logger survived deserialization assertThat(ti.logger).isNotNull(); - boolean condition = ti.getTransactionManager() instanceof SerializableTransactionManager; - assertThat(condition).isTrue(); + assertThat(ti.getTransactionManager()).isInstanceOf(SerializableTransactionManager.class); assertThat(ti.getTransactionAttributeSource()).isNotNull(); } @@ -115,7 +114,7 @@ public class TransactionInterceptorTests extends AbstractTransactionAspectTests ti.setTransactionAttributeSources(tas1, tas2); PlatformTransactionManager ptm = new SerializableTransactionManager(); ti.setTransactionManager(ptm); - ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti); + ti = SerializationTestUtils.serializeAndDeserialize(ti); boolean condition3 = ti.getTransactionManager() instanceof SerializableTransactionManager; assertThat(condition3).isTrue(); diff --git a/spring-tx/src/test/java/org/springframework/transaction/support/JtaTransactionManagerSerializationTests.java b/spring-tx/src/test/java/org/springframework/transaction/support/JtaTransactionManagerSerializationTests.java index 579b7670b12..d5390e33cb0 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/support/JtaTransactionManagerSerializationTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/support/JtaTransactionManagerSerializationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -48,8 +48,7 @@ public class JtaTransactionManagerSerializationTests { SimpleNamingContextBuilder jndiEnv = SimpleNamingContextBuilder .emptyActivatedContextBuilder(); jndiEnv.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut2); - JtaTransactionManager serializedJtatm = (JtaTransactionManager) SerializationTestUtils - .serializeAndDeserialize(jtam); + JtaTransactionManager serializedJtatm = SerializationTestUtils.serializeAndDeserialize(jtam); // should do client-side lookup assertThat(serializedJtatm.logger).as("Logger must survive serialization").isNotNull(); diff --git a/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java b/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java index eb9d95807e0..16121ffc78d 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/SessionScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -171,7 +171,7 @@ public class SessionScopeTests { serializedState = session.serializeState(); assertThat(bean.wasDestroyed()).isFalse(); - serializedState = (Serializable) SerializationTestUtils.serializeAndDeserialize(serializedState); + serializedState = SerializationTestUtils.serializeAndDeserialize(serializedState); session = new MockHttpSession(); session.deserializeState(serializedState);