Skip to content

Commit 033cb76

Browse files
committed
Migrate Mockito-effected test classes to JUnit 5
1 parent eb570ec commit 033cb76

File tree

7 files changed

+80
-123
lines changed

7 files changed

+80
-123
lines changed

spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import java.util.Map;
2323
import java.util.Objects;
2424

25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.Test;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
@@ -38,19 +37,18 @@
3837
import org.springframework.messaging.MessageChannel;
3938
import org.springframework.messaging.PollableChannel;
4039
import org.springframework.messaging.support.GenericMessage;
41-
import org.springframework.test.context.ContextConfiguration;
42-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
40+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4341

4442
import static org.assertj.core.api.Assertions.assertThat;
43+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4544

4645
/**
4746
* @author Mark Fisher
4847
* @author Artem Bilan
4948
*
5049
* @since 2.0
5150
*/
52-
@ContextConfiguration
53-
@RunWith(SpringJUnit4ClassRunner.class)
51+
@SpringJUnitConfig
5452
public class HeaderEnricherTests {
5553

5654
@Autowired
@@ -252,10 +250,13 @@ public void innerBeanWithMethod() {
252250
assertThat(result.getHeaders().get("testHeader")).isEqualTo("testBeanForInnerBeanWithMethod");
253251
}
254252

255-
@Test(expected = BeanDefinitionParsingException.class)
253+
@Test
256254
public void testFailConfigUnexpectedSubElement() {
257-
new ClassPathXmlApplicationContext("HeaderEnricherWithUnexpectedSubElementForHeader-fail-context.xml",
258-
this.getClass()).close();
255+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
256+
.isThrownBy(() ->
257+
new ClassPathXmlApplicationContext(
258+
"HeaderEnricherWithUnexpectedSubElementForHeader-fail-context.xml",
259+
getClass()));
259260
}
260261

261262
@Test

spring-integration-core/src/test/java/org/springframework/integration/config/xml/IdempotentReceiverParserTests.java

Lines changed: 48 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import java.util.Properties;
2323
import java.util.function.BiPredicate;
2424

25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.Test;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.beans.factory.annotation.Qualifier;
@@ -43,19 +42,19 @@
4342
import org.springframework.integration.selector.MetadataStoreSelector;
4443
import org.springframework.messaging.MessageChannel;
4544
import org.springframework.test.annotation.DirtiesContext;
46-
import org.springframework.test.context.ContextConfiguration;
47-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
45+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4846

4947
import static org.assertj.core.api.Assertions.assertThat;
48+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5049
import static org.assertj.core.api.Assertions.fail;
5150
import static org.springframework.integration.test.util.TestUtils.getPropertyValue;
5251

5352
/**
5453
* @author Artem Bilan
54+
*
5555
* @since 4.1
5656
*/
57-
@ContextConfiguration
58-
@RunWith(SpringJUnit4ClassRunner.class)
57+
@SpringJUnitConfig
5958
@DirtiesContext
6059
public class IdempotentReceiverParserTests {
6160

@@ -158,111 +157,72 @@ public void testEmpty() throws Exception {
158157
}
159158

160159
@Test
161-
public void testWithoutEndpoint() throws Exception {
162-
try {
163-
bootStrap("without-endpoint");
164-
fail("BeanDefinitionParsingException expected");
165-
}
166-
catch (BeanDefinitionParsingException e) {
167-
assertThat(e.getMessage()).contains("he 'endpoint' attribute is required");
168-
}
160+
public void testWithoutEndpoint() {
161+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
162+
.isThrownBy(() -> bootStrap("without-endpoint"))
163+
.withMessageContaining("The 'endpoint' attribute is required");
169164
}
170165

171166
@Test
172-
public void testSelectorAndStore() throws Exception {
173-
try {
174-
bootStrap("selector-and-store");
175-
fail("BeanDefinitionParsingException expected");
176-
}
177-
catch (BeanDefinitionParsingException e) {
178-
assertThat(e.getMessage())
179-
.contains("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
180-
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
181-
+ "'compare-values'");
182-
}
167+
public void testSelectorAndStore() {
168+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
169+
.isThrownBy(() -> bootStrap("selector-and-store"))
170+
.withMessageContaining("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
171+
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
172+
+ "'compare-values'");
183173
}
184174

185175
@Test
186-
public void testSelectorAndKeyStrategy() throws Exception {
187-
try {
188-
bootStrap("selector-and-key-strategy");
189-
fail("BeanDefinitionParsingException expected");
190-
}
191-
catch (BeanDefinitionParsingException e) {
192-
assertThat(e.getMessage())
193-
.contains("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
194-
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
195-
+ "'compare-values'");
196-
}
176+
public void testSelectorAndKeyStrategy() {
177+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
178+
.isThrownBy(() -> bootStrap("selector-and-key-strategy"))
179+
.withMessageContaining("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
180+
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
181+
+ "'compare-values'");
197182
}
198183

199184
@Test
200-
public void testSelectorAndKeyExpression() throws Exception {
201-
try {
202-
bootStrap("selector-and-key-expression");
203-
fail("BeanDefinitionParsingException expected");
204-
}
205-
catch (BeanDefinitionParsingException e) {
206-
assertThat(e.getMessage())
207-
.contains("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
208-
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
209-
+ "'compare-values'");
210-
}
185+
public void testSelectorAndKeyExpression() {
186+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
187+
.isThrownBy(() -> bootStrap("selector-and-key-expression"))
188+
.withMessageContaining("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
189+
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
190+
+ "'compare-values'");
211191
}
212192

213193
@Test
214-
public void testSelectorAndValueStrategy() throws Exception {
215-
try {
216-
bootStrap("selector-and-value-strategy");
217-
fail("BeanDefinitionParsingException expected");
218-
}
219-
catch (BeanDefinitionParsingException e) {
220-
assertThat(e.getMessage())
221-
.contains("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
222-
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
223-
+ "'compare-values'");
224-
}
194+
public void testSelectorAndValueStrategy() {
195+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
196+
.isThrownBy(() -> bootStrap("selector-and-value-strategy"))
197+
.withMessageContaining("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
198+
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
199+
+ "'compare-values'");
225200
}
226201

227202
@Test
228-
public void testSelectorAndValueExpression() throws Exception {
229-
try {
230-
bootStrap("selector-and-value-expression");
231-
fail("BeanDefinitionParsingException expected");
232-
}
233-
catch (BeanDefinitionParsingException e) {
234-
assertThat(e.getMessage())
235-
.contains("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
236-
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
237-
+ "'compare-values'");
238-
}
203+
public void testSelectorAndValueExpression() {
204+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
205+
.isThrownBy(() -> bootStrap("selector-and-value-expression"))
206+
.withMessageContaining("The 'selector' attribute is mutually exclusive with 'metadata-store', " +
207+
"'key-strategy', 'key-expression', 'value-strategy', 'value-expression', and "
208+
+ "'compare-values'");
239209
}
240210

241211
@Test
242-
public void testKeyStrategyAndKeyExpression() throws Exception {
243-
try {
244-
bootStrap("key-strategy-and-key-expression");
245-
fail("BeanDefinitionParsingException expected");
246-
}
247-
catch (BeanDefinitionParsingException e) {
248-
assertThat(e.getMessage())
249-
.contains("The 'key-strategy' and 'key-expression' attributes are mutually exclusive");
250-
}
212+
public void testKeyStrategyAndKeyExpression() {
213+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
214+
.isThrownBy(() -> bootStrap("key-strategy-and-key-expression"))
215+
.withMessageContaining("The 'key-strategy' and 'key-expression' attributes are mutually exclusive");
251216
}
252217

253218
@Test
254-
public void testValueStrategyAndValueExpression() throws Exception {
255-
try {
256-
bootStrap("value-strategy-and-value-expression");
257-
fail("BeanDefinitionParsingException expected");
258-
}
259-
catch (BeanDefinitionParsingException e) {
260-
assertThat(e.getMessage())
261-
.contains("The 'value-strategy' and 'value-expression' attributes are mutually exclusive");
262-
}
219+
public void testValueStrategyAndValueExpression() {
220+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
221+
.isThrownBy(() -> bootStrap("value-strategy-and-value-expression"))
222+
.withMessageContaining("The 'value-strategy' and 'value-expression' attributes are mutually exclusive");
263223
}
264224

265-
private ApplicationContext bootStrap(String configProperty) throws Exception {
225+
private static ApplicationContext bootStrap(String configProperty) throws Exception {
266226
PropertiesFactoryBean pfb = new PropertiesFactoryBean();
267227
pfb.setLocation(new ClassPathResource(
268228
"org/springframework/integration/config/xml/idempotent-receiver-configs.properties"));

spring-integration-file/src/test/java/org/springframework/integration/file/config/InboundAdapterWithLockersTests-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<int:channel id="input"/>
4444

4545
<bean id="locker" class="org.mockito.Mockito" factory-method="mock">
46-
<constructor-arg value="org.springframework.integration.file.locking.AbstractFileLockerFilter"/>
46+
<constructor-arg value="org.springframework.integration.file.locking.AbstractFileLockerFilter"
47+
type="java.lang.Class"/>
4748
</bean>
4849
</beans>

spring-integration-file/src/test/java/org/springframework/integration/file/config/InboundAdapterWithLockersTests.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,25 @@
1616

1717
package org.springframework.integration.file.config;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.beans.factory.annotation.Autowired;
2322
import org.springframework.context.ApplicationContext;
2423
import org.springframework.integration.file.locking.NioFileLocker;
2524
import org.springframework.integration.test.util.TestUtils;
26-
import org.springframework.test.context.ContextConfiguration;
27-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2826

2927
import static org.assertj.core.api.Assertions.assertThat;
3028

3129
/**
3230
* @author Oleg Zhurakousky
3331
* @author Gunnar Hillert
32+
* @author Artem Bilan
3433
*
3534
*/
36-
@ContextConfiguration
37-
@RunWith(SpringJUnit4ClassRunner.class)
35+
@SpringJUnitConfig
3836
public class InboundAdapterWithLockersTests {
39-
@Autowired(required = true)
37+
@Autowired
4038
private ApplicationContext context;
4139

4240
@Test
@@ -45,9 +43,9 @@ public void testAdaptersWithLockers() {
4543
.isEqualTo(context.getBean("locker"));
4644
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerB"), "source.scanner.locker"))
4745
.isEqualTo(context.getBean("locker"));
48-
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerC"), "source.scanner.locker")
49-
instanceof NioFileLocker).isTrue();
50-
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerD"), "source.scanner.locker")
51-
instanceof NioFileLocker).isTrue();
46+
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerC"), "source.scanner.locker"))
47+
.isInstanceOf(NioFileLocker.class);
48+
assertThat(TestUtils.getPropertyValue(context.getBean("inputWithLockerD"), "source.scanner.locker"))
49+
.isInstanceOf(NioFileLocker.class);
5250
}
5351
}

spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaInboundChannelAdapterParserTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.jpa.config.xml;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.beans.factory.annotation.Autowired;
2322
import org.springframework.context.ConfigurableApplicationContext;
@@ -30,7 +29,7 @@
3029
import org.springframework.integration.jpa.support.parametersource.ParameterSource;
3130
import org.springframework.integration.test.util.TestUtils;
3231
import org.springframework.test.annotation.DirtiesContext;
33-
import org.springframework.test.context.junit4.SpringRunner;
32+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3433

3534
import static org.assertj.core.api.Assertions.assertThat;
3635

@@ -42,7 +41,7 @@
4241
* @since 2.2
4342
*
4443
*/
45-
@RunWith(SpringRunner.class)
44+
@SpringJUnitConfig
4645
@DirtiesContext
4746
public class JpaInboundChannelAdapterParserTests {
4847

@@ -84,7 +83,7 @@ public void testJpaInboundChannelAdapterParser() throws Exception {
8483
}
8584

8685
@Test
87-
public void testJpaInboundChannelAdapterParserWithMaxResults() throws Exception {
86+
public void testJpaInboundChannelAdapterParserWithMaxResults() {
8887
AbstractMessageChannel outputChannel =
8988
TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "outputChannel", AbstractMessageChannel.class);
9089

@@ -114,7 +113,7 @@ public void testJpaInboundChannelAdapterParserWithMaxResults() throws Exception
114113
}
115114

116115
@Test
117-
public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() throws Exception {
116+
public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() {
118117
AbstractMessageChannel outputChannel =
119118
TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "outputChannel", AbstractMessageChannel.class);
120119

@@ -142,7 +141,7 @@ public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() throws
142141

143142

144143
@Test
145-
public void testJpaExecutorBeanIdNaming() throws Exception {
144+
public void testJpaExecutorBeanIdNaming() {
146145
JpaExecutor jpaExecutor1 = this.context.getBean("jpaInboundChannelAdapter1.jpaExecutor", JpaExecutor.class);
147146
JpaExecutor jpaExecutor2 = this.context.getBean("jpaInboundChannelAdapter2.jpaExecutor", JpaExecutor.class);
148147

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/SftpOutboundGatewayParserTests-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
http://www.springframework.org/schema/integration/sftp https://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd">
99

1010
<bean id="sf" class="org.mockito.Mockito" factory-method="mock">
11-
<constructor-arg value="org.springframework.integration.file.remote.session.SessionFactory"/>
11+
<constructor-arg value="org.springframework.integration.file.remote.session.SessionFactory"
12+
type="java.lang.Class"/>
1213
</bean>
1314

1415
<bean id="csf" class="org.springframework.integration.file.remote.session.CachingSessionFactory">

spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
import java.util.Map;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
2524
import org.springframework.beans.factory.annotation.Qualifier;
@@ -29,8 +28,7 @@
2928
import org.springframework.messaging.MessageChannel;
3029
import org.springframework.messaging.support.GenericMessage;
3130
import org.springframework.test.annotation.DirtiesContext;
32-
import org.springframework.test.context.ContextConfiguration;
33-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3432

3533
import static org.assertj.core.api.Assertions.assertThat;
3634

@@ -40,8 +38,7 @@
4038
*
4139
* @since 2.0
4240
*/
43-
@ContextConfiguration
44-
@RunWith(SpringJUnit4ClassRunner.class)
41+
@SpringJUnitConfig
4542
@DirtiesContext
4643
public class WebServiceHeaderEnricherTests {
4744

0 commit comments

Comments
 (0)