Skip to content

Commit 9387b9f

Browse files
committed
Use try-with-resources in test
1 parent d900867 commit 9387b9f

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/test/java/com/rabbitmq/client/test/StrictExceptionHandlerTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void tooLongClosingMessage() throws Exception {
3939
ConnectionFactory cf = TestUtils.connectionFactory();
4040
final CountDownLatch latch = new CountDownLatch(1);
4141
cf.setExceptionHandler(new StrictExceptionHandler() {
42+
4243
@Override
4344
public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
4445
try {
@@ -49,9 +50,7 @@ public void handleConsumerException(Channel channel, Throwable exception, Consum
4950
latch.countDown();
5051
}
5152
});
52-
Connection c = null;
53-
try {
54-
c = cf.newConnection();
53+
try (Connection c = cf.newConnection()) {
5554
Channel channel = c.createChannel();
5655
String queue = channel.queueDeclare().getQueue();
5756
channel.basicConsume(queue,
@@ -60,10 +59,6 @@ public void handleConsumerException(Channel channel, Throwable exception, Consum
6059
));
6160
channel.basicPublish("", queue, null, new byte[0]);
6261
assertThat(latch.await(5, TimeUnit.SECONDS), is(true));
63-
} finally {
64-
if (c != null) {
65-
c.close();
66-
}
6762
}
6863
}
6964

0 commit comments

Comments
 (0)