1
1
/*
2
- * Copyright 2013-2019 the original author or authors.
2
+ * Copyright 2013-2021 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.
24
24
import javax .management .ObjectName ;
25
25
import javax .management .QueryExp ;
26
26
27
- import org .junit .Test ;
28
- import org .junit .runner .RunWith ;
27
+ import org .junit .jupiter .api .Test ;
29
28
30
29
import org .springframework .beans .factory .annotation .Autowired ;
31
30
import org .springframework .beans .factory .annotation .Qualifier ;
35
34
import org .springframework .messaging .Message ;
36
35
import org .springframework .messaging .PollableChannel ;
37
36
import org .springframework .test .annotation .DirtiesContext ;
38
- import org .springframework .test .context .ContextConfiguration ;
39
- import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
37
+ import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
40
38
41
39
/**
42
40
* @author Stuart Williams
43
41
* @author Gary Russell
44
42
* @author Artem Bilan
45
43
*
46
44
*/
47
- @ ContextConfiguration
48
- @ RunWith (SpringJUnit4ClassRunner .class )
45
+ @ SpringJUnitConfig
49
46
@ DirtiesContext
50
47
public class MBeanTreePollingChannelAdapterParserTests {
51
48
@@ -103,39 +100,39 @@ public class MBeanTreePollingChannelAdapterParserTests {
103
100
private final long testTimeout = 20000L ;
104
101
105
102
@ Test
106
- public void pollDefaultAdapter () throws Exception {
103
+ public void pollDefaultAdapter () {
107
104
adapterDefault .start ();
108
105
109
106
Message <?> result = channel1 .receive (testTimeout );
110
- assertThat (result ).isNotNull ();
111
-
112
- assertThat (result .getPayload ().getClass ()).isEqualTo (HashMap .class );
107
+ assertThat (result )
108
+ .isNotNull ()
109
+ .extracting (Message ::getPayload )
110
+ .isInstanceOf (HashMap .class );
113
111
114
112
@ SuppressWarnings ("unchecked" )
115
113
Map <String , Object > beans = (Map <String , Object >) result .getPayload ();
116
114
117
115
// test for a couple of MBeans
118
- assertThat (beans .containsKey ("java.lang:type=OperatingSystem" )).isTrue ();
119
- assertThat (beans .containsKey ("java.lang:type=Runtime" )).isTrue ();
116
+ assertThat (beans ).containsKeys ("java.lang:type=OperatingSystem" , "java.lang:type=Runtime" );
120
117
121
118
adapterDefault .stop ();
122
119
}
123
120
124
121
@ Test
125
- public void pollInnerAdapter () throws Exception {
122
+ public void pollInnerAdapter () {
126
123
adapterInner .start ();
127
124
128
125
Message <?> result = channel2 .receive (testTimeout );
129
- assertThat (result ).isNotNull ();
130
-
131
- assertThat (result .getPayload ().getClass ()).isEqualTo (HashMap .class );
126
+ assertThat (result )
127
+ .isNotNull ()
128
+ .extracting (Message ::getPayload )
129
+ .isInstanceOf (HashMap .class );
132
130
133
131
@ SuppressWarnings ("unchecked" )
134
132
Map <String , Object > beans = (Map <String , Object >) result .getPayload ();
135
133
136
134
// test for a couple of MBeans
137
- assertThat (beans .containsKey ("java.lang:type=OperatingSystem" )).isTrue ();
138
- assertThat (beans .containsKey ("java.lang:type=Runtime" )).isTrue ();
135
+ assertThat (beans ).containsKeys ("java.lang:type=OperatingSystem" , "java.lang:type=Runtime" );
139
136
140
137
adapterInner .stop ();
141
138
}
@@ -151,73 +148,80 @@ public void pollQueryNameAdapter() throws Exception {
151
148
assertThat (queryExp .apply (new ObjectName ("java.lang:type=Runtime" ))).isTrue ();
152
149
153
150
Message <?> result = channel3 .receive (testTimeout );
154
- assertThat (result ).isNotNull ();
155
-
156
- assertThat (result .getPayload ().getClass ()).isEqualTo (HashMap .class );
151
+ assertThat (result )
152
+ .isNotNull ()
153
+ .extracting (Message ::getPayload )
154
+ .isInstanceOf (HashMap .class );
157
155
158
156
@ SuppressWarnings ("unchecked" )
159
157
Map <String , Object > beans = (Map <String , Object >) result .getPayload ();
160
158
161
159
// test for a couple of MBeans
162
- assertThat (beans .containsKey ("java.lang:type=OperatingSystem" )).isFalse ();
163
- assertThat (beans .containsKey ("java.lang:type=Runtime" )).isTrue ();
160
+ assertThat (beans )
161
+ .containsKey ("java.lang:type=Runtime" )
162
+ .doesNotContainKey ("java.lang:type=OperatingSystem" );
164
163
165
164
adapterQueryName .stop ();
166
165
}
167
166
168
167
@ Test
169
- public void pollQueryNameBeanAdapter () throws Exception {
168
+ public void pollQueryNameBeanAdapter () {
170
169
adapterQueryNameBean .start ();
171
170
172
171
Message <?> result = channel4 .receive (testTimeout );
173
- assertThat (result ).isNotNull ();
174
-
175
- assertThat (result .getPayload ().getClass ()).isEqualTo (HashMap .class );
172
+ assertThat (result )
173
+ .isNotNull ()
174
+ .extracting (Message ::getPayload )
175
+ .isInstanceOf (HashMap .class );
176
176
177
177
@ SuppressWarnings ("unchecked" )
178
178
Map <String , Object > beans = (Map <String , Object >) result .getPayload ();
179
179
180
180
// test for a couple of MBeans
181
- assertThat (beans .containsKey ("java.lang:type=OperatingSystem" )).isTrue ();
182
- assertThat (beans .containsKey ("java.lang:type=Runtime" )).isFalse ();
181
+ assertThat (beans )
182
+ .containsKey ("java.lang:type=OperatingSystem" )
183
+ .doesNotContainKey ("java.lang:type=Runtime" );
183
184
184
185
adapterQueryNameBean .stop ();
185
186
}
186
187
187
188
@ Test
188
- public void pollQueryExprBeanAdapter () throws Exception {
189
+ public void pollQueryExprBeanAdapter () {
189
190
adapterQueryExprBean .start ();
190
191
191
192
Message <?> result = channel5 .receive (testTimeout );
192
- assertThat (result ).isNotNull ();
193
-
194
- assertThat (result .getPayload ().getClass ()).isEqualTo (HashMap .class );
193
+ assertThat (result )
194
+ .isNotNull ()
195
+ .extracting (Message ::getPayload )
196
+ .isInstanceOf (HashMap .class );
195
197
196
198
@ SuppressWarnings ("unchecked" )
197
199
Map <String , Object > beans = (Map <String , Object >) result .getPayload ();
198
200
199
201
// test for a couple of MBeans
200
- assertThat (beans .containsKey ("java.lang:type=OperatingSystem" )).isFalse ();
201
- assertThat (beans .containsKey ("java.lang:type=Runtime" )).isTrue ();
202
+ assertThat (beans )
203
+ .containsKey ("java.lang:type=Runtime" )
204
+ .doesNotContainKey ("java.lang:type=OperatingSystem" );
202
205
203
206
adapterQueryExprBean .stop ();
204
207
}
205
208
206
209
@ Test
207
- public void pollConverterAdapter () throws Exception {
210
+ public void pollConverterAdapter () {
208
211
adapterConverter .start ();
209
212
210
213
Message <?> result = channel6 .receive (testTimeout );
211
- assertThat (result ).isNotNull ();
214
+ assertThat (result )
215
+ .isNotNull ()
216
+ .extracting (Message ::getPayload )
217
+ .isInstanceOf (HashMap .class );
212
218
213
- assertThat (result .getPayload ().getClass ()).isEqualTo (HashMap .class );
214
219
215
220
@ SuppressWarnings ("unchecked" )
216
221
Map <String , Object > beans = (Map <String , Object >) result .getPayload ();
217
222
218
223
// test for a couple of MBeans
219
- assertThat (beans .containsKey ("java.lang:type=OperatingSystem" )).isTrue ();
220
- assertThat (beans .containsKey ("java.lang:type=Runtime" )).isTrue ();
224
+ assertThat (beans ).containsKeys ("java.lang:type=OperatingSystem" , "java.lang:type=Runtime" );
221
225
222
226
adapterConverter .stop ();
223
227
assertThat (TestUtils .getPropertyValue (adapterConverter , "source.converter" )).isSameAs (converter );
0 commit comments