Permalink
Browse files

Inner loop - Red: Test statement formatter

  • Loading branch information...
CarlosMChica committed May 2, 2016
1 parent f999927 commit 1ed74959bbac34e57493b217a644d5e5ce05499d
@@ -34,4 +34,8 @@ public Statement(List<Transaction> transactions) {
@Override public int hashCode() {
return transactions != null ? transactions.hashCode() : 0;
}
public List<StatementLine> lines() {
throw new UnsupportedOperationException();
}
}
@@ -5,6 +5,6 @@
public class StatementFormatter {
public List<ViewStatementLine> format(Statement statement) {
throw new UnsupportedOperationException();
return null;
}
}
@@ -0,0 +1,54 @@
package me.panavtec.androidbankkata.account.statement;
import java.util.Date;
import me.panavtec.androidbankkata.account.transaction.Transaction;
public class StatementLine {
private final Transaction transaction;
private final int runningBalance;
StatementLine(Transaction transaction, int runningBalance) {
this.transaction = transaction;
this.runningBalance = runningBalance;
}
public Date date() {
return transaction.getDate();
}
public int amount() {
return transaction.getAmount();
}
public int runningBalance() {
return runningBalance;
}
@Override public String toString() {
return "StatementLine{" +
"transaction=" + transaction +
", runningBalance=" + runningBalance +
'}';
}
@Override public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
StatementLine that = (StatementLine) o;
return runningBalance == that.runningBalance && transaction != null ? transaction.equals(
that.transaction) : that.transaction == null;
}
@Override public int hashCode() {
int result = transaction != null ? transaction.hashCode() : 0;
result = 31 * result + runningBalance;
return result;
}
}
@@ -0,0 +1,48 @@
package me.panavtec.androidbankkata.account.statement;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import me.panavtec.androidbankkata.ViewStatementLine;
import me.panavtec.androidbankkata.account.transaction.Deposit;
import me.panavtec.androidbankkata.account.transaction.Withdrawal;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static java.util.Arrays.asList;
import static java.util.Calendar.JANUARY;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
@RunWith(MockitoJUnitRunner.class) public class StatementFormatterShould {
@Mock StatementView view;
@Mock Statement statement;
@Test
public void format_statement_containing_all_transactions_in_reverse_chronologically_order() {
StatementFormatter formatter = new StatementFormatter();
given(statement.lines()).willReturn(lines());
List<ViewStatementLine> lines = formatter.format(statement);
List<ViewStatementLine> expectedViewLines =
asList(new ViewStatementLine("14/01/2012", "-500", "2500"),
new ViewStatementLine("13/01/2012", "2000", "3000"),
new ViewStatementLine("10/01/2012", "1000", "1000"));
assertThat(lines, is(expectedViewLines));
}
private List<StatementLine> lines() {
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 static Date date(int year, int month, int day) {
return new GregorianCalendar(year, month, day).getTime();
}
}

0 comments on commit 1ed7495

Please sign in to comment.