Skip to content

Commit d574e66

Browse files
committed
Use AssertJ instead of JUnit assertions in JMS tests
1 parent cb59ad8 commit d574e66

File tree

6 files changed

+68
-65
lines changed

6 files changed

+68
-65
lines changed

deps/rabbit/test/amqp_jms_SUITE_data/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
<version>${assertj.version}</version>
5151
<scope>test</scope>
5252
</dependency>
53+
<!-- add explicitly to update automatically with dependabot -->
54+
<dependency>
55+
<groupId>com.google.googlejavaformat</groupId>
56+
<artifactId>google-java-format</artifactId>
57+
<version>${google-java-format.version}</version>
58+
<scope>test</scope>
59+
</dependency>
5360

5461
</dependencies>
5562
<build>

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/Cli.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
// The Original Code is RabbitMQ.
1212
//
1313
// The Initial Developer of the Original Code is Pivotal Software, Inc.
14-
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
14+
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
15+
// and/or its subsidiaries. All rights reserved.
1516
//
1617
package com.rabbitmq.amqp.tests.jms;
1718

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/JmsConnectionTest.java

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import static com.rabbitmq.amqp.tests.jms.Cli.startBroker;
2020
import static com.rabbitmq.amqp.tests.jms.Cli.stopBroker;
2121
import static com.rabbitmq.amqp.tests.jms.TestUtils.*;
22-
import static org.junit.jupiter.api.Assertions.assertNotNull;
23-
import static org.junit.jupiter.api.Assertions.assertThrows;
24-
import static org.junit.jupiter.api.Assertions.assertTrue;
25-
import static org.junit.jupiter.api.Assertions.fail;
22+
import static org.assertj.core.api.Assertions.*;
2623

2724
import jakarta.jms.*;
2825
import java.util.concurrent.CountDownLatch;
@@ -46,27 +43,26 @@ public class JmsConnectionTest {
4643
@Timeout(30)
4744
public void testCreateConnection() throws Exception {
4845
try (Connection connection = factory.createConnection()) {
49-
assertNotNull(connection);
46+
assertThat(connection).isNotNull();
5047
}
5148
}
5249

5350
@Test
5451
@Timeout(30)
5552
public void testCreateConnectionAndStart() throws Exception {
5653
try (Connection connection = factory.createConnection()) {
57-
assertNotNull(connection);
54+
assertThat(connection).isNotNull();
5855
connection.start();
5956
}
6057
}
6158

6259
@Test
6360
@Timeout(30)
64-
// Currently not supported by RabbitMQ.
65-
@Disabled
61+
@Disabled("Client ID conflict detection is not supported by RabbitMQ")
6662
public void testCreateWithDuplicateClientIdFails() throws Exception {
6763
JmsConnection connection1 = (JmsConnection) factory.createConnection();
6864
connection1.setClientID("Test");
69-
assertNotNull(connection1);
65+
assertThat(connection1).isNotNull();
7066
connection1.start();
7167
JmsConnection connection2 = (JmsConnection) factory.createConnection();
7268
try {
@@ -84,15 +80,15 @@ public void testCreateWithDuplicateClientIdFails() throws Exception {
8480

8581
@Test
8682
public void testSetClientIdAfterStartedFails() {
87-
assertThrows(
88-
JMSException.class,
89-
() -> {
90-
try (Connection connection = factory.createConnection()) {
91-
connection.setClientID("Test");
92-
connection.start();
93-
connection.setClientID("NewTest");
94-
}
95-
});
83+
assertThatThrownBy(
84+
() -> {
85+
try (Connection connection = factory.createConnection()) {
86+
connection.setClientID("Test");
87+
connection.start();
88+
connection.setClientID("NewTest");
89+
}
90+
})
91+
.isInstanceOf(JMSException.class);
9692
}
9793

9894
@Test
@@ -103,7 +99,7 @@ public void testCreateConnectionAsSystemAdmin() throws Exception {
10399
f.setUsername(adminUsername());
104100
f.setPassword(adminPassword());
105101
try (Connection connection = factory.createConnection()) {
106-
assertNotNull(connection);
102+
assertThat(connection).isNotNull();
107103
connection.start();
108104
}
109105
}
@@ -112,38 +108,38 @@ public void testCreateConnectionAsSystemAdmin() throws Exception {
112108
@Timeout(30)
113109
public void testCreateConnectionCallSystemAdmin() throws Exception {
114110
try (Connection connection = factory.createConnection(adminUsername(), adminPassword())) {
115-
assertNotNull(connection);
111+
assertThat(connection).isNotNull();
116112
connection.start();
117113
}
118114
}
119115

120116
@Test
121117
@Timeout(30)
122118
public void testCreateConnectionAsUnknownUser() {
123-
assertThrows(
124-
JMSSecurityException.class,
125-
() -> {
126-
JmsConnectionFactory f = (JmsConnectionFactory) factory;
127-
f.setUsername("unknown");
128-
f.setPassword("unknown");
129-
try (Connection connection = factory.createConnection()) {
130-
assertNotNull(connection);
131-
connection.start();
132-
}
133-
});
119+
assertThatThrownBy(
120+
() -> {
121+
JmsConnectionFactory f = (JmsConnectionFactory) factory;
122+
f.setUsername("unknown");
123+
f.setPassword("unknown");
124+
try (Connection connection = factory.createConnection()) {
125+
assertThat(connection).isNotNull();
126+
connection.start();
127+
}
128+
})
129+
.isInstanceOf(JMSSecurityException.class);
134130
}
135131

136132
@Test
137133
@Timeout(30)
138134
public void testCreateConnectionCallUnknownUser() {
139-
assertThrows(
140-
JMSSecurityException.class,
141-
() -> {
142-
try (Connection connection = factory.createConnection("unknown", "unknown")) {
143-
assertNotNull(connection);
144-
connection.start();
145-
}
146-
});
135+
assertThatThrownBy(
136+
() -> {
137+
try (Connection connection = factory.createConnection("unknown", "unknown")) {
138+
assertThat(connection).isNotNull();
139+
connection.start();
140+
}
141+
})
142+
.isInstanceOf(JMSSecurityException.class);
147143
}
148144

149145
@Test
@@ -180,11 +176,11 @@ public void testConnectionExceptionBrokerStop() throws Exception {
180176
connection.setExceptionListener(exception -> latch.countDown());
181177
connection.start();
182178
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
183-
assertNotNull(session);
179+
assertThat(session).isNotNull();
184180

185181
try {
186182
stopBroker();
187-
assertTrue(latch.await(10, TimeUnit.SECONDS));
183+
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
188184
} finally {
189185
startBroker();
190186
}

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/JmsTemporaryQueueTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package com.rabbitmq.amqp.tests.jms;
1818

1919
import static com.rabbitmq.amqp.tests.jms.TestUtils.brokerUri;
20-
import static org.junit.jupiter.api.Assertions.*;
21-
import static org.junit.jupiter.api.Assertions.fail;
20+
import static org.assertj.core.api.Assertions.*;
2221

2322
import jakarta.jms.*;
2423
import jakarta.jms.IllegalStateException;
@@ -56,14 +55,14 @@ public void testCreatePublishConsumeTemporaryQueue() throws Exception {
5655
connection.start();
5756

5857
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
59-
assertNotNull(session);
58+
assertThat(session).isNotNull();
6059
TemporaryQueue queue = session.createTemporaryQueue();
6160
MessageConsumer consumer = session.createConsumer(queue);
6261

6362
MessageProducer producer = session.createProducer(queue);
6463
String body = UUID.randomUUID().toString();
6564
producer.send(session.createTextMessage(body));
66-
assertEquals(body, consumer.receive(60_000).getBody(String.class));
65+
assertThat(consumer.receive(60_000).getBody(String.class)).isEqualTo(body);
6766
}
6867

6968
@Test

deps/rabbit/test/amqp_jms_SUITE_data/src/test/java/com/rabbitmq/amqp/tests/jms/JmsTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static com.rabbitmq.amqp.tests.jms.TestUtils.protonClient;
2020
import static com.rabbitmq.amqp.tests.jms.TestUtils.protonConnection;
2121
import static org.assertj.core.api.Assertions.assertThat;
22-
import static org.junit.jupiter.api.Assertions.*;
22+
import static org.assertj.core.api.Assertions.fail;
2323

2424
import com.rabbitmq.qpid.protonj2.client.Client;
2525
import com.rabbitmq.qpid.protonj2.client.Delivery;
@@ -49,15 +49,15 @@ public void message_types_jms_to_jms(Queue queue) throws Exception {
4949
TextMessage textMessage = session.createTextMessage(msg1);
5050
producer.send(textMessage);
5151
TextMessage receivedTextMessage = (TextMessage) consumer.receive(5000);
52-
assertEquals(msg1, receivedTextMessage.getText());
52+
assertThat(receivedTextMessage.getText()).isEqualTo(msg1);
5353

5454
// BytesMessage
5555
String msg2 = "msg2";
5656
BytesMessage bytesMessage = session.createBytesMessage();
5757
bytesMessage.writeUTF(msg2);
5858
producer.send(bytesMessage);
5959
BytesMessage receivedBytesMessage = (BytesMessage) consumer.receive(5000);
60-
assertEquals(msg2, receivedBytesMessage.readUTF());
60+
assertThat(receivedBytesMessage.readUTF()).isEqualTo(msg2);
6161

6262
// MapMessage
6363
MapMessage mapMessage = session.createMapMessage();
@@ -67,10 +67,10 @@ public void message_types_jms_to_jms(Queue queue) throws Exception {
6767
mapMessage.setLong("key4", 1L);
6868
producer.send(mapMessage);
6969
MapMessage receivedMapMessage = (MapMessage) consumer.receive(5000);
70-
assertEquals("value", receivedMapMessage.getString("key1"));
71-
assertEquals(true, receivedMapMessage.getBoolean("key2"));
72-
assertEquals(1.0, receivedMapMessage.getDouble("key3"));
73-
assertEquals(1L, receivedMapMessage.getLong("key4"));
70+
assertThat(receivedMapMessage.getString("key1")).isEqualTo("value");
71+
assertThat(receivedMapMessage.getBoolean("key2")).isTrue();
72+
assertThat(receivedMapMessage.getDouble("key3")).isEqualTo(1.0);
73+
assertThat(receivedMapMessage.getLong("key4")).isEqualTo(1L);
7474

7575
// StreamMessage
7676
StreamMessage streamMessage = session.createStreamMessage();
@@ -80,18 +80,18 @@ public void message_types_jms_to_jms(Queue queue) throws Exception {
8080
streamMessage.writeLong(1L);
8181
producer.send(streamMessage);
8282
StreamMessage receivedStreamMessage = (StreamMessage) consumer.receive(5000);
83-
assertEquals("value", receivedStreamMessage.readString());
84-
assertEquals(true, receivedStreamMessage.readBoolean());
85-
assertEquals(1.0, receivedStreamMessage.readDouble());
86-
assertEquals(1L, receivedStreamMessage.readLong());
83+
assertThat(receivedStreamMessage.readString()).isEqualTo("value");
84+
assertThat(receivedStreamMessage.readBoolean()).isTrue();
85+
assertThat(receivedStreamMessage.readDouble()).isEqualTo(1.0);
86+
assertThat(receivedStreamMessage.readLong()).isEqualTo(1L);
8787

8888
// ObjectMessage
8989
ObjectMessage objectMessage = session.createObjectMessage();
9090
ArrayList<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));
9191
objectMessage.setObject(list);
9292
producer.send(objectMessage);
9393
ObjectMessage receivedObjectMessage = (ObjectMessage) consumer.receive(5000);
94-
assertEquals(list, receivedObjectMessage.getObject());
94+
assertThat(receivedObjectMessage.getObject()).isEqualTo(list);
9595
}
9696
}
9797

@@ -127,11 +127,11 @@ public void message_types_jms_to_amqp(Queue queue) throws Exception {
127127
com.rabbitmq.qpid.protonj2.client.Connection amqpConnection = protonConnection(client)) {
128128
Receiver receiver = amqpConnection.openReceiver(queue.getQueueName());
129129
Delivery delivery = receiver.receive(10, TimeUnit.SECONDS);
130-
assertNotNull(delivery);
131-
assertEquals(msg1, delivery.message().body());
130+
assertThat(delivery).isNotNull();
131+
assertThat(delivery.message().body()).isEqualTo(msg1);
132132

133133
delivery = receiver.receive(10, TimeUnit.SECONDS);
134-
assertNotNull(delivery);
134+
assertThat(delivery).isNotNull();
135135
com.rabbitmq.qpid.protonj2.client.Message<Map<String, Object>> mapMessage =
136136
delivery.message();
137137
assertThat(mapMessage.body())
@@ -141,7 +141,7 @@ public void message_types_jms_to_amqp(Queue queue) throws Exception {
141141
.containsEntry("key4", -1L);
142142

143143
delivery = receiver.receive(10, TimeUnit.SECONDS);
144-
assertNotNull(delivery);
144+
assertThat(delivery).isNotNull();
145145
com.rabbitmq.qpid.protonj2.client.Message<List<Object>> listMessage = delivery.message();
146146
assertThat(listMessage.body()).containsExactly("value", true, -1.1, -1L);
147147
}
@@ -174,7 +174,7 @@ public void temporary_queue_rpc(Queue requestQueue) throws Exception {
174174
}
175175

176176
TextMessage clientResponseMessage = (TextMessage) clientConsumer.receive(5000);
177-
assertEquals("HELLO", clientResponseMessage.getText());
177+
assertThat(clientResponseMessage.getText()).isEqualTo("HELLO");
178178
}
179179
}
180180

@@ -188,7 +188,7 @@ public void temporary_queue_delete() throws Exception {
188188
clientContext.createProducer().send(queue, "hello");
189189
fail("should not be able to create producer for deleted temporary queue");
190190
} catch (IllegalStateRuntimeException expectedException) {
191-
assertEquals("Temporary destination has been deleted", expectedException.getMessage());
191+
assertThat(expectedException).hasMessage("Temporary destination has been deleted");
192192
}
193193
}
194194
}

deps/rabbit/test/amqp_jms_SUITE_data/src/test/resources/logback-test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</encoder>
66
</appender>
77

8-
<logger name="com.rabbitmq" level="info" />
8+
<logger name="com.rabbitmq" level="warn" />
99

1010
<root level="warn">
1111
<appender-ref ref="STDOUT" />

0 commit comments

Comments
 (0)