Skip to content

Commit 12cc5d8

Browse files
committed
Refactor AbsentQueue test with lambdas
1 parent 21e0f35 commit 12cc5d8

File tree

1 file changed

+15
-39
lines changed

1 file changed

+15
-39
lines changed

src/test/java/com/rabbitmq/client/test/server/AbsentQueue.java

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
package com.rabbitmq.client.test.server;
1818

19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.fail;
19+
import com.rabbitmq.client.AMQP;
20+
import com.rabbitmq.client.Channel;
21+
import com.rabbitmq.client.test.functional.ClusteredTestBase;
22+
import org.junit.Test;
2123

2224
import java.io.IOException;
25+
import java.util.concurrent.Callable;
2326
import java.util.concurrent.TimeoutException;
2427

25-
import com.rabbitmq.client.Channel;
26-
import org.junit.Test;
27-
28-
import com.rabbitmq.client.AMQP;
29-
import com.rabbitmq.client.test.functional.ClusteredTestBase;
28+
import static org.junit.Assert.assertFalse;
29+
import static org.junit.Assert.fail;
3030

3131
/**
3232
* This tests whether 'absent' queues - durable queues whose home node
@@ -56,39 +56,19 @@ public class AbsentQueue extends ClusteredTestBase {
5656
alternateChannel.queueDelete(Q);
5757
}
5858

59-
@Test public void notFound() throws IOException, InterruptedException {
59+
@Test public void notFound() throws Exception {
6060
waitPropagationInHa();
61-
assertNotFound(new Task() {
62-
public void run() throws IOException {
63-
channel.queueDeclare(Q, true, false, false, null);
64-
}
65-
});
66-
assertNotFound(new Task() {
67-
public void run() throws IOException {
68-
channel.queueDeclarePassive(Q);
69-
}
70-
});
71-
assertNotFound(new Task() {
72-
public void run() throws IOException {
73-
channel.queuePurge(Q);
74-
}
75-
});
76-
assertNotFound(new Task() {
77-
public void run() throws IOException {
78-
channel.basicGet(Q, true);
79-
}
80-
});
81-
assertNotFound(new Task() {
82-
public void run() throws IOException {
83-
channel.queueBind(Q, "amq.fanout", "", null);
84-
}
85-
});
61+
assertNotFound(() -> channel.queueDeclare(Q, true, false, false, null));
62+
assertNotFound(() -> channel.queueDeclarePassive(Q));
63+
assertNotFound(() -> channel.queuePurge(Q));
64+
assertNotFound(() -> channel.basicGet(Q, true));
65+
assertNotFound(() -> channel.queueBind(Q, "amq.fanout", "", null));
8666
}
8767

88-
protected void assertNotFound(Task t) throws IOException {
68+
protected void assertNotFound(Callable<?> t) throws Exception {
8969
if (clusteredChannel == null) return;
9070
try {
91-
t.run();
71+
t.call();
9272
if (!HATests.HA_TESTS_RUNNING) fail("expected not_found");
9373
} catch (IOException ioe) {
9474
assertFalse(HATests.HA_TESTS_RUNNING);
@@ -116,8 +96,4 @@ private void waitPropagationInHa() throws IOException, InterruptedException {
11696
}
11797
}
11898

119-
private interface Task {
120-
void run() throws IOException;
121-
}
122-
12399
}

0 commit comments

Comments
 (0)