1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
import org .springframework .aop .support .DefaultPointcutAdvisor ;
26
26
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
27
27
import org .springframework .beans .factory .xml .XmlBeanDefinitionReader ;
28
- import org .springframework .core .io .Resource ;
29
28
import org .springframework .tests .aop .interceptor .SerializableNopInterceptor ;
30
29
import org .springframework .tests .sample .beans .Person ;
31
30
import org .springframework .tests .sample .beans .SerializablePerson ;
41
40
*/
42
41
public class HotSwappableTargetSourceTests {
43
42
44
- private static final Resource CONTEXT = qualifiedResource (HotSwappableTargetSourceTests .class , "context.xml" );
45
-
46
43
/** Initial count value set in bean factory XML */
47
44
private static final int INITIAL_COUNT = 10 ;
48
45
49
46
private DefaultListableBeanFactory beanFactory ;
50
47
48
+
51
49
@ Before
52
- public void setUp () throws Exception {
50
+ public void setup () {
53
51
this .beanFactory = new DefaultListableBeanFactory ();
54
- new XmlBeanDefinitionReader (this .beanFactory ).loadBeanDefinitions (CONTEXT );
52
+ new XmlBeanDefinitionReader (this .beanFactory ).loadBeanDefinitions (
53
+ qualifiedResource (HotSwappableTargetSourceTests .class , "context.xml" ));
55
54
}
56
55
57
56
/**
58
57
* We must simulate container shutdown, which should clear threads.
59
58
*/
60
59
@ After
61
- public void tearDown () {
60
+ public void close () {
62
61
// Will call pool.close()
63
62
this .beanFactory .destroySingletons ();
64
63
}
65
64
65
+
66
66
/**
67
67
* Check it works like a normal invoker
68
- *
69
68
*/
70
69
@ Test
71
70
public void testBasicFunctionality () {
@@ -106,18 +105,13 @@ public void testValidSwaps() {
106
105
assertEquals (target1 .getCount (), proxied .getCount ());
107
106
}
108
107
109
-
110
- /**
111
- *
112
- * @param invalid
113
- * @return the message
114
- */
115
- private IllegalArgumentException testRejectsSwapToInvalidValue (Object invalid ) {
108
+ @ Test
109
+ public void testRejectsSwapToNull () {
116
110
HotSwappableTargetSource swapper = (HotSwappableTargetSource ) beanFactory .getBean ("swapper" );
117
111
IllegalArgumentException aopex = null ;
118
112
try {
119
- swapper .swap (invalid );
120
- fail ("Shouldn't be able to swap to invalid value [" + invalid + "] " );
113
+ swapper .swap (null );
114
+ fail ("Shouldn't be able to swap to invalid value" );
121
115
}
122
116
catch (IllegalArgumentException ex ) {
123
117
// Ok
@@ -126,19 +120,9 @@ private IllegalArgumentException testRejectsSwapToInvalidValue(Object invalid) {
126
120
127
121
// It shouldn't be corrupted, it should still work
128
122
testBasicFunctionality ();
129
- return aopex ;
123
+ assertTrue ( aopex . getMessage (). contains ( "null" )) ;
130
124
}
131
125
132
- @ Test
133
- public void testRejectsSwapToNull () {
134
- IllegalArgumentException ex = testRejectsSwapToInvalidValue (null );
135
- assertTrue (ex .getMessage ().contains ("null" ));
136
- }
137
-
138
- // TODO test reject swap to wrong interface or class?
139
- // how to decide what's valid?
140
-
141
-
142
126
@ Test
143
127
public void testSerialization () throws Exception {
144
128
SerializablePerson sp1 = new SerializablePerson ();
@@ -165,4 +149,5 @@ public void testSerialization() throws Exception {
165
149
assertEquals (sp1 .getName (), p .getName ());
166
150
167
151
}
152
+
168
153
}
0 commit comments