Transactions { public Transaction byId(String id) { checkNotNull(id); for (Transaction transaction : transactions) { if (transaction.getId().equals(id)) { return transaction; } } return null; } Transactions();  Transactions(List<Transaction> transactions);  Transactions(Transaction... transactions); List<Transaction> getTransactions(); Transaction byId(String id); Transactions copyWithReplacement(Transaction transaction);  }
@Test public void byId() { Transaction t1 = MockTransaction.create("2015-01-02", "a", 123); Transaction t2 = MockTransaction.create("2015-01-02", "a", 123); Transactions transactions = new Transactions(ImmutableList.of(t1, t2)); assertSame(t1, transactions.byId(t1.getId())); assertSame(t2, transactions.byId(t2.getId())); assertEquals(null, transactions.byId("not here")); }