Permalink
Browse files

Inner loop - Blue: Clean up statement lines generation imp and test

  • Loading branch information...
CarlosMChica committed May 2, 2016
1 parent 6763139 commit 8f4e26cd2f9387c9f8d0102a026f4f6ef58bcc7d
@@ -19,12 +19,20 @@ public Statement(List<Transaction> transactions) {
AtomicInteger currentBalance = new AtomicInteger(0);
ArrayList<StatementLine> lines = new ArrayList<>();
for (Transaction transaction : transactions) {
lines.add(new StatementLine(transaction, currentBalance.addAndGet(transaction.getAmount())));
lines.add(line(transaction, currentBalance));
}
return lines;
}
private StatementLine line(Transaction transaction, AtomicInteger runningBalance) {
return new StatementLine(transaction, nextRunningBalance(runningBalance, transaction));
}
private int nextRunningBalance(AtomicInteger runningBalance, Transaction transaction) {
return runningBalance.addAndGet(transaction.getAmount());
}
@Override public String toString() {
return "Statement{" +
"transactions=" + transactions +
@@ -16,15 +16,21 @@
public class StatementShould {
@Test public void generate_statement_lines_with_running_balance() {
Statement statement = new Statement(transactions());
Statement statement = givenStatementWithTransactions();
List<StatementLine> lines = statement.lines();
List<StatementLine> expectedLines =
asList(new StatementLine(new Deposit(1000, date(2012, JANUARY, 10)), 1000),
new StatementLine(new Deposit(2000, date(2012, JANUARY, 13)), 3000),
new StatementLine(new Withdrawal(500, date(2012, JANUARY, 14)), 2500));
assertThat(lines, is(expectedLines));
assertThat(lines, is(linesFromTransactions()));
}
private List<StatementLine> linesFromTransactions() {
return asList(new StatementLine(new Deposit(1000, date(2012, JANUARY, 10)), 1000),
new StatementLine(new Deposit(2000, date(2012, JANUARY, 13)), 3000),
new StatementLine(new Withdrawal(500, date(2012, JANUARY, 14)), 2500));
}
private Statement givenStatementWithTransactions() {
return new Statement(transactions());
}
private List<Transaction> transactions() {

0 comments on commit 8f4e26c

Please sign in to comment.