Permalink
Browse files

Inner loop - Green: Implement show account statement

  • Loading branch information...
CarlosMChica committed May 2, 2016
1 parent 0a0af11 commit dd1a92aaf6b6480ac2dbfcdaf29188fdcb2b7611
@@ -1,5 +1,8 @@
package me.panavtec.androidbankkata.account;
+import java.util.List;
+import me.panavtec.androidbankkata.ViewStatementLine;
+import me.panavtec.androidbankkata.account.statement.Statement;
import me.panavtec.androidbankkata.account.statement.StatementFormatter;
import me.panavtec.androidbankkata.account.statement.StatementView;
import me.panavtec.androidbankkata.account.transaction.Deposit;
@@ -8,15 +11,19 @@
public class BankAccount {
- private TransactionRepository repository;
- private Clock clock;
+ private final TransactionRepository repository;
+ private final StatementFormatter formatter;
+ private final Clock clock;
+ private StatementView view;
public BankAccount(TransactionRepository repository, StatementFormatter formatter, Clock clock) {
this.repository = repository;
+ this.formatter = formatter;
this.clock = clock;
}
public void attach(StatementView view) {
+ this.view = view;
}
public void deposit(int amount) {
@@ -28,5 +35,10 @@ public void withdraw(int amount) {
}
public void showStatement() {
+ view.show(statementLines());
+ }
+
+ private List<ViewStatementLine> statementLines() {
+ return formatter.format(new Statement(repository.transactions()));
}
}
@@ -4,6 +4,34 @@
import me.panavtec.androidbankkata.account.transaction.Transaction;
public class Statement {
+ private List<Transaction> transactions;
+
public Statement(List<Transaction> transactions) {
+ this.transactions = transactions;
+ }
+
+ @Override public String toString() {
+ return "Statement{" +
+ "transactions=" + transactions +
+ '}';
+ }
+
+ @Override public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Statement statement = (Statement) o;
+
+ return transactions != null
+ ? transactions.equals(statement.transactions)
+ : statement.transactions == null;
+ }
+
+ @Override public int hashCode() {
+ return transactions != null ? transactions.hashCode() : 0;
}
}
@@ -1,7 +1,10 @@
package me.panavtec.androidbankkata.account.statement;
+import java.util.List;
+import me.panavtec.androidbankkata.ViewStatementLine;
+
public class StatementFormatter {
- public void format(Statement statement) {
+ public List<ViewStatementLine> format(Statement statement) {
throw new UnsupportedOperationException();
}
}
@@ -28,7 +28,7 @@
@Mock StatementView view;
@Mock Clock clock;
- @Test public void store_a_transaction() {
+ @Test public void store_a_deposit_transaction() {
BankAccount account = givenAccountWithMockedClock();
account.deposit(anAmount());

0 comments on commit dd1a92a

Please sign in to comment.