Polish SerializationTestUtils, clean up warnings, etc.
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user