1
1
/*
2
- * Copyright 2002-2007 the original author or authors.
2
+ * Copyright 2002-2009 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.
17
17
package org .springframework .test .context ;
18
18
19
19
import static org .junit .Assert .assertEquals ;
20
- import static org .junit .Assert .fail ;
21
20
22
21
import org .junit .Test ;
23
-
24
22
import org .springframework .test .context .support .AbstractTestExecutionListener ;
25
23
26
24
/**
27
25
* <p>
28
- * JUnit 4 based unit test for the
29
- * {@link TestExecutionListeners @TestExecutionListeners} annotation, which
30
- * verifies:
26
+ * JUnit 4 based unit test for the {@link TestExecutionListeners
27
+ * @TestExecutionListeners} annotation, which verifies:
31
28
* </p>
32
29
* <ul>
33
30
* <li>Proper registering of {@link TestExecutionListener listeners} in
36
33
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3896"
37
34
* target="_blank">SPR-3896</a></li>
38
35
* </ul>
39
- *
36
+ *
40
37
* @author Sam Brannen
41
38
* @since 2.5
42
39
*/
@@ -46,75 +43,78 @@ public class TestExecutionListenersTests {
46
43
public void verifyNumDefaultListenersRegistered () throws Exception {
47
44
TestContextManager testContextManager = new TestContextManager (DefaultListenersExampleTestCase .class );
48
45
assertEquals ("Verifying the number of registered TestExecutionListeners for DefaultListenersExampleTest." , 3 ,
49
- testContextManager .getTestExecutionListeners ().size ());
46
+ testContextManager .getTestExecutionListeners ().size ());
50
47
}
51
48
52
49
@ Test
53
50
public void verifyNumNonInheritedDefaultListenersRegistered () throws Exception {
54
- TestContextManager testContextManager = new TestContextManager (NonInheritedDefaultListenersExampleTestCase .class );
51
+ TestContextManager testContextManager = new TestContextManager (
52
+ NonInheritedDefaultListenersExampleTestCase .class );
55
53
assertEquals (
56
- "Verifying the number of registered TestExecutionListeners for NonInheritedDefaultListenersExampleTest." ,
57
- 1 , testContextManager .getTestExecutionListeners ().size ());
54
+ "Verifying the number of registered TestExecutionListeners for NonInheritedDefaultListenersExampleTest." ,
55
+ 1 , testContextManager .getTestExecutionListeners ().size ());
58
56
}
59
57
60
58
@ Test
61
59
public void verifyNumInheritedDefaultListenersRegistered () throws Exception {
62
60
TestContextManager testContextManager = new TestContextManager (InheritedDefaultListenersExampleTestCase .class );
63
61
assertEquals (
64
- "Verifying the number of registered TestExecutionListeners for InheritedDefaultListenersExampleTest." ,
65
- 1 , testContextManager .getTestExecutionListeners ().size ());
62
+ "Verifying the number of registered TestExecutionListeners for InheritedDefaultListenersExampleTest." , 1 ,
63
+ testContextManager .getTestExecutionListeners ().size ());
66
64
67
65
testContextManager = new TestContextManager (SubInheritedDefaultListenersExampleTestCase .class );
68
66
assertEquals (
69
- "Verifying the number of registered TestExecutionListeners for SubInheritedDefaultListenersExampleTest." ,
70
- 1 , testContextManager .getTestExecutionListeners ().size ());
67
+ "Verifying the number of registered TestExecutionListeners for SubInheritedDefaultListenersExampleTest." ,
68
+ 1 , testContextManager .getTestExecutionListeners ().size ());
71
69
72
70
testContextManager = new TestContextManager (SubSubInheritedDefaultListenersExampleTestCase .class );
73
71
assertEquals (
74
- "Verifying the number of registered TestExecutionListeners for SubSubInheritedDefaultListenersExampleTest." ,
75
- 2 , testContextManager .getTestExecutionListeners ().size ());
72
+ "Verifying the number of registered TestExecutionListeners for SubSubInheritedDefaultListenersExampleTest." ,
73
+ 2 , testContextManager .getTestExecutionListeners ().size ());
76
74
}
77
75
78
76
@ Test
79
77
public void verifyNumListenersRegistered () throws Exception {
80
78
TestContextManager testContextManager = new TestContextManager (ExampleTestCase .class );
81
79
assertEquals ("Verifying the number of registered TestExecutionListeners for ExampleTest." , 3 ,
82
- testContextManager .getTestExecutionListeners ().size ());
80
+ testContextManager .getTestExecutionListeners ().size ());
83
81
}
84
82
85
83
@ Test
86
84
public void verifyNumNonInheritedListenersRegistered () throws Exception {
87
85
TestContextManager testContextManager = new TestContextManager (NonInheritedListenersExampleTestCase .class );
88
86
assertEquals ("Verifying the number of registered TestExecutionListeners for NonInheritedListenersExampleTest." ,
89
- 1 , testContextManager .getTestExecutionListeners ().size ());
87
+ 1 , testContextManager .getTestExecutionListeners ().size ());
90
88
}
91
89
92
90
@ Test
93
91
public void verifyNumInheritedListenersRegistered () throws Exception {
94
92
TestContextManager testContextManager = new TestContextManager (InheritedListenersExampleTestCase .class );
95
93
assertEquals ("Verifying the number of registered TestExecutionListeners for InheritedListenersExampleTest." , 4 ,
96
- testContextManager .getTestExecutionListeners ().size ());
94
+ testContextManager .getTestExecutionListeners ().size ());
95
+ }
96
+
97
+ @ Test (expected = IllegalStateException .class )
98
+ public void verifyDuplicateListenersConfigThrowsException () throws Exception {
99
+ new TestContextManager (DuplicateListenersConfigExampleTestCase .class );
97
100
}
98
101
99
102
100
103
static class DefaultListenersExampleTestCase {
101
104
}
102
105
103
- @ TestExecutionListeners ( { QuuxTestExecutionListener .class } )
106
+ @ TestExecutionListeners (QuuxTestExecutionListener .class )
104
107
static class InheritedDefaultListenersExampleTestCase extends DefaultListenersExampleTestCase {
105
- public void testDoSomething () {
106
- fail ("whaa?" );
107
- }
108
108
}
109
109
110
110
static class SubInheritedDefaultListenersExampleTestCase extends InheritedDefaultListenersExampleTestCase {
111
111
}
112
112
113
- @ TestExecutionListeners ( { EnigmaTestExecutionListener .class } )
113
+ @ TestExecutionListeners (EnigmaTestExecutionListener .class )
114
114
static class SubSubInheritedDefaultListenersExampleTestCase extends SubInheritedDefaultListenersExampleTestCase {
115
115
}
116
116
117
- @ TestExecutionListeners (value = { QuuxTestExecutionListener .class }, inheritListeners = false )
117
+ @ TestExecutionListeners (listeners = { QuuxTestExecutionListener .class }, inheritListeners = false )
118
118
static class NonInheritedDefaultListenersExampleTestCase extends InheritedDefaultListenersExampleTestCase {
119
119
}
120
120
@@ -123,14 +123,18 @@ static class NonInheritedDefaultListenersExampleTestCase extends InheritedDefaul
123
123
static class ExampleTestCase {
124
124
}
125
125
126
- @ TestExecutionListeners ( { QuuxTestExecutionListener .class } )
126
+ @ TestExecutionListeners (QuuxTestExecutionListener .class )
127
127
static class InheritedListenersExampleTestCase extends ExampleTestCase {
128
128
}
129
129
130
- @ TestExecutionListeners (value = { QuuxTestExecutionListener .class } , inheritListeners = false )
130
+ @ TestExecutionListeners (listeners = QuuxTestExecutionListener .class , inheritListeners = false )
131
131
static class NonInheritedListenersExampleTestCase extends InheritedListenersExampleTestCase {
132
132
}
133
133
134
+ @ TestExecutionListeners (listeners = FooTestExecutionListener .class , value = BarTestExecutionListener .class )
135
+ static class DuplicateListenersConfigExampleTestCase {
136
+ }
137
+
134
138
static class FooTestExecutionListener extends AbstractTestExecutionListener {
135
139
}
136
140
@@ -146,4 +150,4 @@ static class QuuxTestExecutionListener extends AbstractTestExecutionListener {
146
150
static class EnigmaTestExecutionListener extends AbstractTestExecutionListener {
147
151
}
148
152
149
- }
153
+ }
0 commit comments