Skip to content

Commit f8a3744

Browse files
committed
GH-3055: Deprecate JUnit 4 classes in the project
Fixes: #3055 JUnit 4 is no longer actively maintained, and the last maintenance release was JUnit 4.13.2 in February 2021. In addition, JUnit 4 has a Java 1.5 baseline. Furthermore, the JUnit team is planning to release JUnit 6.0 with a Java 17 baseline later this year. Since JUnit 5 support has been deprecated in Spring Framework, we also follow same theme and deprecate for removal JUnit 4 rules implementations in favor of respective utils for JUnit 5
1 parent f803718 commit f8a3744

File tree

13 files changed

+138
-260
lines changed

13 files changed

+138
-260
lines changed

build.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ ext {
5050
hibernateValidationVersion = '8.0.2.Final'
5151
jacksonBomVersion = '2.18.3'
5252
jaywayJsonPathVersion = '2.9.0'
53-
junit4Version = '4.13.2'
5453
junitJupiterVersion = '5.12.2'
5554
kotlinCoroutinesVersion = '1.10.2'
5655
log4jVersion = '2.24.3'
@@ -442,9 +441,6 @@ project('spring-rabbit') {
442441
testRuntimeOnly 'com.fasterxml.jackson.core:jackson-databind'
443442
testRuntimeOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
444443
testRuntimeOnly 'com.fasterxml.jackson.module:jackson-module-kotlin'
445-
testRuntimeOnly("junit:junit:$junit4Version") {
446-
exclude group: 'org.hamcrest', module: 'hamcrest-core'
447-
}
448444
}
449445
}
450446

@@ -503,9 +499,6 @@ project('spring-rabbit-junit') {
503499
api 'org.junit.jupiter:junit-jupiter-api'
504500
api "org.assertj:assertj-core:$assertjVersion"
505501

506-
optionalApi("junit:junit:$junit4Version") {
507-
exclude group: 'org.hamcrest', module: 'hamcrest-core'
508-
}
509502
optionalApi 'org.testcontainers:rabbitmq'
510503
optionalApi 'org.testcontainers:junit-jupiter'
511504
optionalApi "ch.qos.logback:logback-classic:$logbackVersion"

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/BrokerRunning.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
*
6363
* @since 1.7
6464
*
65+
* @deprecated since 4.0 in favor of JUnit 5 {@link RabbitAvailable}.
6566
*/
67+
@Deprecated(since = "4.0", forRemoval = true)
6668
public final class BrokerRunning extends TestWatcher {
6769

6870
private static final Log LOGGER = LogFactory.getLog(BrokerRunningSupport.class);

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/JUnitUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ public static void revertLevels(String methodName, LevelsContainer container) {
131131
((Logger) LogManager.getLogger(key)).setLevel(value);
132132
}
133133
});
134-
container.oldLevels.forEach((key, value) -> {
135-
if (!key.equals(BrokerRunning.class)) {
136-
((Logger) LogManager.getLogger(key)).setLevel(value);
137-
}
138-
});
139134
// container.oldLbLevels.forEach((key, value) ->
140135
// ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(key)).setLevel(value));
141136
}

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/LogLevelAdjuster.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,16 +32,19 @@
3232
* A JUnit method @Rule that changes the logger level for a set of classes
3333
* while a test method is running. Useful for performance or scalability tests
3434
* where we don't want to generate a large log in a tight inner loop.
35-
*
35+
* <p>
3636
* As well as adjusting Log4j, this also adjusts loggers for logback. The amqp-client
37-
* library now uses slf4j. Since we have logback on the CP (for the appender)
37+
* library now uses Slf4J. Since we have logback on the CP (for the appender)
3838
* we can't add the slf4j-log4j bridge as well.
3939
*
4040
* @author Dave Syer
4141
* @author Artem Bilan
4242
* @author Gary Russell
4343
*
44+
* @deprecated since 4.0 in favor of JUnit 5 {@link LogLevels}.
45+
*
4446
*/
47+
@Deprecated(since = "4.0", forRemoval = true)
4548
public class LogLevelAdjuster implements MethodRule {
4649

4750
private final List<Class<?>> classes;

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/LongRunning.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 the original author or authors.
2+
* Copyright 2017-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,8 +30,9 @@
3030
* the value that {@link Boolean#parseBoolean(String)} evaluates to {@code true}.
3131
*
3232
* @author Gary Russell
33-
* @since 2.0.2
33+
* @author Artem Bilan
3434
*
35+
* @since 2.0.2
3536
*/
3637
@ExtendWith(LongRunningIntegrationTestCondition.class)
3738
@Target({ ElementType.TYPE })
@@ -40,10 +41,10 @@
4041
public @interface LongRunning {
4142

4243
/**
43-
* The name of the variable/property used to determine whether long running tests
44+
* The name of the variable/property used to determine whether long-running tests
4445
* should run.
4546
* @return the name of the variable/property.
4647
*/
47-
String value() default LongRunningIntegrationTest.RUN_LONG_INTEGRATION_TESTS;
48+
String value() default LongRunningIntegrationTestCondition.RUN_LONG_INTEGRATION_TESTS;
4849

4950
}

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/LongRunningIntegrationTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2019 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,19 +24,23 @@
2424
import org.junit.runners.model.Statement;
2525

2626
/**
27-
* Rule to prevent long running tests from running on every build; set environment
27+
* Rule to prevent long-running tests from running on every build; set environment
2828
* variable RUN_LONG_INTEGRATION_TESTS on a CI nightly build to ensure coverage.
2929
*
3030
* @author Gary Russell
3131
* @author Artem Bilan
32+
*
3233
* @since 1.2.1
3334
*
35+
* @deprecated since 4.0 in favor of JUnit 5 {@link LongRunning}.
3436
*/
37+
@Deprecated(since = "4.0", forRemoval = true)
3538
public class LongRunningIntegrationTest extends TestWatcher {
3639

3740
private static final Log logger = LogFactory.getLog(LongRunningIntegrationTest.class); // NOSONAR - lower case
3841

39-
public static final String RUN_LONG_INTEGRATION_TESTS = "RUN_LONG_INTEGRATION_TESTS";
42+
public static final String RUN_LONG_INTEGRATION_TESTS =
43+
LongRunningIntegrationTestCondition.RUN_LONG_INTEGRATION_TESTS;
4044

4145
private boolean shouldRun = false;
4246

@@ -56,7 +60,7 @@ public LongRunningIntegrationTest(String property) {
5660
@Override
5761
public Statement apply(Statement base, Description description) {
5862
if (!this.shouldRun) {
59-
logger.info("Skipping long running test " + description.toString());
63+
logger.info("Skipping long running test " + description);
6064
}
6165
Assume.assumeTrue(this.shouldRun);
6266
return super.apply(base, description);

spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/LongRunningIntegrationTestCondition.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,15 +28,20 @@
2828
import org.springframework.util.StringUtils;
2929

3030
/**
31-
* {@link ExecutionCondition} to skip long running tests unless an environment
31+
* {@link ExecutionCondition} to skip long-running tests unless an environment
3232
* variable or property is set.
3333
*
3434
* @author Gary Russell
35+
* @author Artem Bilan
36+
*
3537
* @since 2.0.2
38+
*
3639
* @see LongRunning
3740
*/
3841
public class LongRunningIntegrationTestCondition implements ExecutionCondition {
3942

43+
public static final String RUN_LONG_INTEGRATION_TESTS = "RUN_LONG_INTEGRATION_TESTS";
44+
4045
private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled(
4146
"@LongRunning is not present");
4247

@@ -50,7 +55,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
5055
LongRunning longRunning = mergedAnnotation.synthesize();
5156
String property = longRunning.value();
5257
if (!StringUtils.hasText(property)) {
53-
property = LongRunningIntegrationTest.RUN_LONG_INTEGRATION_TESTS;
58+
property = RUN_LONG_INTEGRATION_TESTS;
5459
}
5560
return JUnitUtils.parseBooleanProperty(property)
5661
? ConditionEvaluationResult.enabled("Long running tests must run")
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
2-
* Provides support classes (Rules etc. with no spring-rabbit dependencies) for JUnit
3-
* tests.
2+
* Provides support classes for JUnit tests.
43
*/
54
@org.jspecify.annotations.NullMarked
65
package org.springframework.amqp.rabbit.junit;

spring-rabbit-junit/src/test/java/org/springframework/amqp/rabbit/junit/BrokerRunningTests.java

Lines changed: 0 additions & 80 deletions
This file was deleted.

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateIntegrationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import org.springframework.amqp.rabbit.connection.PublisherCallbackChannelImpl;
8080
import org.springframework.amqp.rabbit.connection.RabbitResourceHolder;
8181
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
82-
import org.springframework.amqp.rabbit.junit.BrokerRunning;
8382
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
8483
import org.springframework.amqp.rabbit.junit.LogLevels;
8584
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
@@ -146,8 +145,7 @@
146145
RabbitTemplateIntegrationTests.NO_CORRELATION})
147146
@LogLevels(classes = {RabbitTemplate.class, DirectMessageListenerContainer.class,
148147
DirectReplyToMessageListenerContainer.class,
149-
RabbitAdmin.class, RabbitTemplateIntegrationTests.class, BrokerRunning.class,
150-
ClosingRecoveryListener.class},
148+
RabbitAdmin.class, RabbitTemplateIntegrationTests.class, ClosingRecoveryListener.class},
151149
level = "DEBUG")
152150
@DirtiesContext
153151
public class RabbitTemplateIntegrationTests {

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainerIntegrationTests.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
4949
import org.springframework.amqp.rabbit.core.RabbitAdmin;
5050
import org.springframework.amqp.rabbit.core.RabbitTemplate;
51-
import org.springframework.amqp.rabbit.junit.BrokerRunning;
5251
import org.springframework.amqp.rabbit.junit.BrokerRunningSupport;
5352
import org.springframework.amqp.rabbit.junit.LogLevels;
5453
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
@@ -89,15 +88,15 @@
8988
* @since 2.0
9089
*
9190
*/
92-
@RabbitAvailable(queues = { DirectMessageListenerContainerIntegrationTests.Q1,
91+
@RabbitAvailable(queues = {DirectMessageListenerContainerIntegrationTests.Q1,
9392
DirectMessageListenerContainerIntegrationTests.Q2,
9493
DirectMessageListenerContainerIntegrationTests.Q3,
9594
DirectMessageListenerContainerIntegrationTests.EQ1,
9695
DirectMessageListenerContainerIntegrationTests.EQ2,
97-
DirectMessageListenerContainerIntegrationTests.DLQ1 })
98-
@LogLevels(classes = { CachingConnectionFactory.class, DirectReplyToMessageListenerContainer.class,
99-
DirectMessageListenerContainer.class, DirectMessageListenerContainerIntegrationTests.class,
100-
BrokerRunning.class }, level = "DEBUG")
96+
DirectMessageListenerContainerIntegrationTests.DLQ1})
97+
@LogLevels(classes = {CachingConnectionFactory.class, DirectReplyToMessageListenerContainer.class,
98+
DirectMessageListenerContainer.class, DirectMessageListenerContainerIntegrationTests.class},
99+
level = "DEBUG")
101100
public class DirectMessageListenerContainerIntegrationTests {
102101

103102
public static final String Q1 = "testQ1.DirectMessageListenerContainerIntegrationTests";
@@ -309,7 +308,7 @@ public void testQueueManagementQueueInstances() throws Exception {
309308
container.setConsumerTagStrategy(new Tag());
310309
container.afterPropertiesSet();
311310
container.setQueues(new Queue(Q1));
312-
assertThat(container.getQueueNames()).isEqualTo(new String[]{Q1});
311+
assertThat(container.getQueueNames()).isEqualTo(new String[] {Q1});
313312
container.start();
314313
container.addQueues(new Queue(Q2));
315314
assertThat(consumersOnQueue(Q1, 2)).isTrue();
@@ -392,7 +391,8 @@ else if (event instanceof ListenerContainerConsumerTerminatedEvent) {
392391
latch2.countDown();
393392
}
394393
});
395-
container.setMessageListener(m -> { });
394+
container.setMessageListener(m -> {
395+
});
396396
container.setIdleEventInterval(50L);
397397
container.setBeanName("events");
398398
container.setConsumerTagStrategy(new Tag());
@@ -563,7 +563,8 @@ private void testRecoverDeletedQueueGuts(boolean autoDeclare, BrokerRunningSuppo
563563
container.setQueueNames(Q1, Q2);
564564
container.setConsumersPerQueue(2);
565565
container.setConsumersPerQueue(2);
566-
container.setMessageListener(m -> { });
566+
container.setMessageListener(m -> {
567+
});
567568
container.setFailedDeclarationRetryInterval(500);
568569
container.setBeanName("deleteQauto=" + autoDeclare);
569570
container.setConsumerTagStrategy(new Tag());
@@ -650,7 +651,8 @@ public void testNonManagedContainerDoesntStartWhenConnectionFactoryDestroyed() t
650651
});
651652

652653
DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
653-
container.setMessageListener(m -> { });
654+
container.setMessageListener(m -> {
655+
});
654656
container.setQueueNames(Q1);
655657
container.setBeanName("stopAfterDestroyBeforeStart");
656658
container.afterPropertiesSet();
@@ -741,6 +743,7 @@ public void testMessageAckListenerWithSuccessfulAck() throws Exception {
741743
final CountDownLatch latch = new CountDownLatch(1);
742744
container.setQueueNames(Q1);
743745
container.setMessageListener(new MessageListener() {
746+
744747
@Override
745748
public void onMessage(Message message) {
746749
}
@@ -777,6 +780,7 @@ public void testMessageAckListenerWithFailedAck() throws Exception {
777780
final CountDownLatch latch = new CountDownLatch(1);
778781
container.setQueueNames(Q1);
779782
container.setMessageListener(new MessageListener() {
783+
780784
@Override
781785
public void onMessage(Message message) {
782786
cf.resetConnection();
@@ -914,4 +918,5 @@ public String createConsumerTag(String queue) {
914918
}
915919

916920
}
921+
917922
}

0 commit comments

Comments
 (0)