### Question:
Web3jService implements BlockchainService { @Override public TransactionReceipt getTransactionReceipt(String txId) { try { final EthGetTransactionReceipt response = web3j.ethGetTransactionReceipt(txId).send(); return response .getTransactionReceipt() .map(receipt -> new Web3jTransactionReceipt(receipt)) .orElse(null); } catch (IOException e) { throw new BlockchainException("Unable to connect to the ethereum client", e); } } Web3jService(String nodeName,
                        Web3j web3j,
                        ContractEventDetailsFactory eventDetailsFactory,
                        AsyncTaskService asyncTaskService); @Override List<ContractEventDetails> retrieveEvents(ContractEventFilter eventFilter,
                                                     BigInteger startBlock,
                                                     BigInteger endBlock); @Override FilterSubscription registerEventListener(ContractEventFilter eventFilter,
                                                    ContractEventListener eventListener,
                                                    BigInteger startBlock,
                                                    BigInteger endBlock,
                                                    Optional<Runnable> onCompletion); @Override String getClientVersion(); @Override TransactionReceipt getTransactionReceipt(String txId); @Override BigInteger getCurrentBlockNumber(); Optional<Block> getBlock(String blockHash, boolean fullTransactionObjects); List<ContractEventDetails> getEventsForFilter(ContractEventFilter filter, BigInteger blockNumber); @Override String getRevertReason(String from, String to, BigInteger blockNumber, String input);  }### Answer:
@Test public void testGetTransactionReceiptHappyPath() throws IOException { final Request<?, EthGetTransactionReceipt> mockRequest = mock(Request.class); final EthGetTransactionReceipt mockGetTxReceipt = mock(EthGetTransactionReceipt.class); final org.web3j.protocol.core.methods.response.TransactionReceipt mockTxReceipt = createMockTxReceipt(); final Optional<org.web3j.protocol.core.methods.response.TransactionReceipt> txReceiptOptional = Optional.ofNullable(mockTxReceipt); when(mockGetTxReceipt.getTransactionReceipt()).thenReturn(txReceiptOptional); when(mockRequest.send()).thenReturn(mockGetTxReceipt); doReturn(mockRequest).when(mockWeb3j).ethGetTransactionReceipt(TX_HASH); checkTransactionReceipt(underTest.getTransactionReceipt(TX_HASH)); }
@Test(expected = BlockchainException.class) public void testGetTransactionReceiptIOException() throws IOException { final Request<?, EthGetTransactionReceipt> mockRequest = mock(Request.class); when(mockRequest.send()).thenThrow(new IOException()); doReturn(mockRequest).when(mockWeb3j).ethGetTransactionReceipt(TX_HASH); underTest.getTransactionReceipt(TX_HASH); }