Program: 85770
Project: 85770
Buggy source:
@Test public void announce() throws Exception {
  FakeChannel p1=connectPeer(1,new VersionMessage(params,2));
  FakeChannel p2=connectPeer(2);
  assertNotNull(peerGroup.getDownloadPeer());
  control.replay();
  peerGroup.setMinBroadcastConnections(2);
  Block b1=TestUtils.makeSolvedTestBlock(blockStore,address);
  inbound(p1,b1);
  assertNull(outbound(p1));
  assertEquals(Utils.toNanoCoins(50,0),wallet.getBalance());
  final Transaction[] transactions=new Transaction[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onTransactionConfidenceChanged(    Wallet wallet,    Transaction tx){
      transactions[0]=tx;
    }
  }
);
  Address dest=new ECKey().toAddress(params);
  Wallet.SendResult sendResult=wallet.sendCoins(peerGroup,dest,Utils.toNanoCoins(1,0));
  assertNotNull(sendResult.tx);
  Threading.waitForUserCode();
  assertFalse(sendResult.broadcastComplete.isDone());
  assertEquals(transactions[0],sendResult.tx);
  assertEquals(transactions[0].getConfidence().numBroadcastPeers(),1);
  transactions[0]=null;
  Transaction t1=(Transaction)outbound(p1);
  assertNotNull(t1);
  assertEquals(Utils.toNanoCoins(49,0),t1.getValueSentToMe(wallet));
  InventoryMessage inv=new InventoryMessage(params);
  inv.addTransaction(t1);
  inbound(p2,inv);
  Threading.waitForUserCode();
  assertTrue(sendResult.broadcastComplete.isDone());
  assertEquals(transactions[0],sendResult.tx);
  assertEquals(transactions[0].getConfidence().numBroadcastPeers(),2);
  Block b2=TestUtils.createFakeBlock(blockStore,t1).block;
  inbound(p1,b2);
  assertNull(outbound(p1));
  peerGroup.removeWallet(wallet);
  Wallet.SendRequest req=Wallet.SendRequest.to(dest,Utils.toNanoCoins(2,0));
  req.ensureMinRequiredFee=false;
  Transaction t3=wallet.sendCoinsOffline(req);
  assertNull(outbound(p1));
  peerGroup.addWallet(wallet);
  InventoryMessage inv1=(InventoryMessage)outbound(p1);
  assertEquals(t3.getHash(),inv1.getItems().get(0).hash);
  GetDataMessage getdata=new GetDataMessage(params);
  getdata.addItem(inv1.getItems().get(0));
  inbound(p1,getdata);
  Transaction t4=(Transaction)outbound(p1);
  assertEquals(t3,t4);
  FakeChannel p3=connectPeer(3);
  assertTrue(outbound(p3) instanceof InventoryMessage);
  control.verify();
}

Fixed version (ground truth):
@Test public void announce() throws Exception {
  FakeChannel p1=connectPeer(1,new VersionMessage(params,2));
  FakeChannel p2=connectPeer(2);
  assertNotNull(peerGroup.getDownloadPeer());
  control.replay();
  peerGroup.setMinBroadcastConnections(2);
  Block b1=TestUtils.makeSolvedTestBlock(blockStore,address);
  inbound(p1,b1);
  assertNull(outbound(p1));
  assertEquals(Utils.toNanoCoins(50,0),wallet.getBalance());
  final Transaction[] transactions=new Transaction[1];
  wallet.addEventListener(new AbstractWalletEventListener(){
    @Override public void onTransactionConfidenceChanged(    Wallet wallet,    Transaction tx){
      transactions[0]=tx;
    }
  }
);
  Address dest=new ECKey().toAddress(params);
  Wallet.SendResult sendResult=wallet.sendCoins(peerGroup,dest,Utils.toNanoCoins(1,0));
  assertNotNull(sendResult.tx);
  Threading.waitForUserCode();
  assertFalse(sendResult.broadcastComplete.isDone());
  assertEquals(transactions[0],sendResult.tx);
  assertEquals(transactions[0].getConfidence().numBroadcastPeers(),1);
  transactions[0]=null;
  Transaction t1=(Transaction)outbound(p1);
  assertNotNull(t1);
  assertEquals(Utils.toNanoCoins(49,0),t1.getValueSentToMe(wallet));
  InventoryMessage inv=new InventoryMessage(params);
  inv.addTransaction(t1);
  inbound(p2,inv);
  Threading.waitForUserCode();
  assertTrue(sendResult.broadcastComplete.isDone());
  assertEquals(transactions[0],sendResult.tx);
  assertEquals(2,transactions[0].getConfidence().numBroadcastPeers());
  Block b2=TestUtils.createFakeBlock(blockStore,t1).block;
  inbound(p1,b2);
  assertNull(outbound(p1));
  peerGroup.removeWallet(wallet);
  Wallet.SendRequest req=Wallet.SendRequest.to(dest,Utils.toNanoCoins(2,0));
  req.ensureMinRequiredFee=false;
  Transaction t3=checkNotNull(wallet.sendCoinsOffline(req));
  assertNull(outbound(p1));
  peerGroup.addWallet(wallet);
  assertEquals(t3.getHash(),((Transaction)outbound(p1)).getHash());
}