GRPCClient implements HLAPI { @Override public void registerRejectListener(RejectListener rejectListener) throws HLAPIException { observer.subscribeToRejections(rejectListener); } GRPCClient(String host, int port, int observerPort); @Override String getClientVersion(); @Override String getServerVersion(); @Override long ping(long nonce); @Override void addAlertListener(AlertListener listener); @Override void removeAlertListener(AlertListener listener); @Override int getChainHeight(); @Override HLAPIHeader getBlockHeader(BID hash); @Override HLAPIBlock getBlock(BID hash); @Override HLAPITransaction getTransaction(TID hash); @Override void sendTransaction(Transaction transaction); @Override void registerRejectListener(RejectListener rejectListener); @Override void removeRejectListener(RejectListener rejectListener); @Override void sendBlock(Block block); @Override void registerTransactionListener(TransactionListener listener); @Override void removeTransactionListener(TransactionListener listener); @Override void registerTrunkListener(TrunkListener listener); @Override void removeTrunkListener(TrunkListener listener); @Override void catchUp(List<BID> inventory, int limit, boolean headers, TrunkListener listener);  }
@Test public void rejectListener() throws HLAPIException, InterruptedException, ExecutionException { class InvalidTransaction extends Transaction { public InvalidTransaction() { super(new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); } @Override public byte[] toByteArray() { return new byte[0]; } } MeasurableTransaction tx = new MeasurableTransaction(new InvalidTransaction(), unlimited); client.registerRejectListener((command, hash, reason, rejectionCode) -> { tx.complete(); }); tx.send(client); tx.get(); }