@Test
public void coinAgeOrdering() throws Exception {

    // Send three transactions in four blocks on top of each other. Coin age of t1 is 1*4=4, coin age of t2 = 2*2=4
    // and t3=0.01.
    Transaction t1 = checkNotNull(sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN));
    // Padding block.
    wallet.notifyNewBestBlock(FakeTxBuilder.createFakeBlock(blockStore, Block.BLOCK_HEIGHT_GENESIS).storedBlock);
    final Coin TWO_COINS = COIN.multiply(2);
    Transaction t2 = checkNotNull(sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, TWO_COINS));
    Transaction t3 = checkNotNull(sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT));
    // Should be ordered t2, t1, t3.
    ArrayList<TransactionOutput> candidates = new ArrayList<TransactionOutput>();
    candidates.add(t3.getOutput(0));
    candidates.add(t2.getOutput(0));
    candidates.add(t1.getOutput(0));
    DefaultCoinSelector.sortOutputs(candidates);
    assertEquals(t2.getOutput(0), candidates.get(0));
    assertEquals(t1.getOutput(0), candidates.get(1));
    assertEquals(t3.getOutput(0), candidates.get(2));
}