@Test
public void rejectHandling() throws Exception {

    InboundMessageQueuer[] channels = { connectPeer(0), connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) };
    Transaction tx = FakeTxBuilder.createFakeTx(UNITTEST);
    TransactionBroadcast broadcast = new TransactionBroadcast(peerGroup, tx);
    ListenableFuture<Transaction> future = broadcast.broadcast();
    // 0 and 3 are randomly selected to receive the broadcast.
    assertEquals(tx, outbound(channels[1]));
    assertEquals(tx, outbound(channels[2]));
    assertEquals(tx, outbound(channels[4]));
    RejectMessage reject = new RejectMessage(UNITTEST, RejectMessage.RejectCode.DUST, tx.getHash(), "tx", "dust");
    inbound(channels[1], reject);
    inbound(channels[4], reject);
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertEquals(RejectedTransactionException.class, e.getCause().getClass());
    }
}