1
public static BigInteger OriginalMethod(){

// connect to node
Web3j web3 = Web3j.build(new HttpService());  // defaults to 
http://localhost:8545/

// send asynchronous requests to get balance
EthGetBalance ethGetBalance = web3
.ethGetBalance("0xAccountAddress", DefaultBlockParameterName.LATEST)
.sendAsync()
.get();

BigInteger wei = ethGetBalance.getBalance();
}


public static BigInteger MockOriginalMethod(){
web3j=Mockito.mock(Web3j.class);//Mock web3j class
        BigInteger bigValue=Mockito.mock(BigInteger.class);
        Mockito.when(web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST).sendAsync()
                .get().getBalance()).thenReturn(bigValue);
return bigValue.valueOf(11);
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.