package net.pterodactylus.fcp.quelaton;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@Test
public void waitingForConnectionClosureWorks() throws IOException, ExecutionException, InterruptedException {
- replySequence.setExpectedMessage("ConnectionClosed");
+ replySequence.setExpectedMessage("none");
Future<Boolean> result = replySequence.send(fcpMessage);
Throwable throwable = new Throwable();
replySequence.connectionClosed(fcpConnection, throwable);
- assertThat(result.get(), is(true));
- assertThat(replySequence.receivedThrowable.get(), is(throwable));
+ try {
+ result.get();
+ } catch (ExecutionException e) {
+ Throwable t = e;
+ while (t.getCause() != null) {
+ t = t.getCause();
+ }
+ assertThat(t, sameInstance(throwable));
+ }
}
@FunctionalInterface
private final AtomicReference<String> gotMessage = new AtomicReference<>();
private final AtomicReference<String> expectedMessage = new AtomicReference<>();
- private final AtomicReference<Throwable> receivedThrowable = new AtomicReference<>();
public TestFcpReplySequence(ExecutorService executorService, FcpConnection fcpConnection) {
super(executorService, fcpConnection);
gotMessage.set(fcpMessage.getName());
}
- @Override
- protected void consumeConnectionClosed(Throwable throwable) {
- receivedThrowable.set(throwable);
- gotMessage.set("ConnectionClosed");
- }
-
}
}