@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(); assertEquals(tx, outbound(channels[1])); assertEquals(tx, outbound(channels[2])); assertEquals(tx, outbound(channels[4])); RejectMessage reject = new RejectMessage(UNITTEST, RejectMessage.RejectCode.DUST, tx.getTxId(), "tx", "dust"); inbound(channels[1], reject); inbound(channels[4], reject); try { future.get(); fail(); } catch (ExecutionException e) { assertEquals(RejectedTransactionException.class, e.getCause().getClass()); } }
public ListenableFuture<Transaction> broadcast() { peerGroup.addPreMessageReceivedEventListener(Threading.SAME_THREAD, rejectionListener); log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size()); peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD); return future; }
TransactionBroadcast { public ListenableFuture<Transaction> broadcast() { peerGroup.addPreMessageReceivedEventListener(Threading.SAME_THREAD, rejectionListener); log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size()); peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD); return future; } }
TransactionBroadcast { public ListenableFuture<Transaction> broadcast() { peerGroup.addPreMessageReceivedEventListener(Threading.SAME_THREAD, rejectionListener); log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size()); peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD); return future; } TransactionBroadcast(PeerGroup peerGroup, Transaction tx); private  TransactionBroadcast(Transaction tx); }
TransactionBroadcast { public ListenableFuture<Transaction> broadcast() { peerGroup.addPreMessageReceivedEventListener(Threading.SAME_THREAD, rejectionListener); log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size()); peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD); return future; } TransactionBroadcast(PeerGroup peerGroup, Transaction tx); private  TransactionBroadcast(Transaction tx); @VisibleForTesting static TransactionBroadcast createMockBroadcast(Transaction tx, final SettableFuture<Transaction> future); ListenableFuture<Transaction> future(); void setMinConnections(int minConnections); void setDropPeersAfterBroadcast(boolean dropPeersAfterBroadcast); ListenableFuture<Transaction> broadcast(); void setProgressCallback(ProgressCallback callback); void setProgressCallback(ProgressCallback callback, @Nullable Executor executor); }
TransactionBroadcast { public ListenableFuture<Transaction> broadcast() { peerGroup.addPreMessageReceivedEventListener(Threading.SAME_THREAD, rejectionListener); log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size()); peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD); return future; } TransactionBroadcast(PeerGroup peerGroup, Transaction tx); private  TransactionBroadcast(Transaction tx); @VisibleForTesting static TransactionBroadcast createMockBroadcast(Transaction tx, final SettableFuture<Transaction> future); ListenableFuture<Transaction> future(); void setMinConnections(int minConnections); void setDropPeersAfterBroadcast(boolean dropPeersAfterBroadcast); ListenableFuture<Transaction> broadcast(); void setProgressCallback(ProgressCallback callback); void setProgressCallback(ProgressCallback callback, @Nullable Executor executor); @VisibleForTesting
    static Random random; }