BitcoinjBlockchainServiceImpl implements BlockChainService { @Override public String generateCentralWalletHash() throws BlockchainException { try { final org.bitcoinj.core.Wallet receiver = this.centralWallet(); String freshHash = null; Transaction transaction = null; do { freshHash = this.getFreshHash(freshHash, receiver); transaction = this.transactionService.getByReceiverHash(freshHash); } while (transaction != null); this.saveCentralWallet(receiver); return freshHash; } catch (final UnreadableWalletException e) { log.error("error during hash generation", e); throw new BlockchainException(e); } catch (final IOException e) { log.error("cannot save central wallet", e); throw new BlockchainException(e); } }  void init(); Wallet saveCentralWallet(
            final org.bitcoinj.core.Wallet blockchainWallet); @Override String send(final Transaction transaction); @Override String generateCentralWalletHash();  }
@Test public void testGenerateCentralWalletHashWithTransaction() throws BlockchainException { when(this.transactionService.getByReceiverHash(anyString())).thenReturn(null, this.transaction, null); when(this.walletService.create(any(Wallet.class))).thenAnswer(new Answer<Wallet>() { @Override public Wallet answer(final InvocationOnMock invocation) throws Throwable { final Wallet wallet = invocation.getArgumentAt(0, Wallet.class); FileUtils.write(new File("src/test/resources/content1.cnt"), wallet.getContent()); return wallet; } }); final String hash1 = this.service.generateCentralWalletHash(); final String hash2 = this.service.generateCentralWalletHash(); Assert.assertNotSame(hash1, hash2); }
@Test public void testGenerateCentralWalletHash() throws BlockchainException { when(this.transactionService.getByReceiverHash(anyString())).thenReturn(null); when(this.walletService.create(any(Wallet.class))).thenAnswer(new Answer<Wallet>() { @Override public Wallet answer(final InvocationOnMock invocation) throws Throwable { final Wallet wallet = invocation.getArgumentAt(0, Wallet.class); FileUtils.write(new File("src/test/resources/content1.cnt"), wallet.getContent()); return wallet; } }); final String hash1 = this.service.generateCentralWalletHash(); final String hash2 = this.service.generateCentralWalletHash(); Assert.assertFalse(hash1.equals(hash2)); }