Permalink
Browse files

Inner loop - Green: Implement store transaction

  • Loading branch information...
1 parent a1f8701 commit 1f5cdab3fa5f1bfcdb4b9b2eb85da209db0cb9e9 @CarlosMChica committed May 2, 2016
@@ -2,18 +2,24 @@
import me.panavtec.androidbankkata.account.statement.StatementFormatter;
import me.panavtec.androidbankkata.account.statement.StatementView;
+import me.panavtec.androidbankkata.account.transaction.Transaction;
import me.panavtec.androidbankkata.account.transaction.TransactionRepository;
public class BankAccount {
- public BankAccount(TransactionRepository repository, StatementFormatter formatter, Clock clock) {
+ private TransactionRepository repository;
+ private Clock clock;
+ public BankAccount(TransactionRepository repository, StatementFormatter formatter, Clock clock) {
+ this.repository = repository;
+ this.clock = clock;
}
public void attach(StatementView view) {
}
public void deposit(int amount) {
+ repository.store(new Transaction(amount, clock.today()));
}
public void withdraw(int amount) {
@@ -3,7 +3,40 @@
import java.util.Date;
public class Transaction {
+ private final int amount;
+ private final Date date;
+
public Transaction(int amount, Date date) {
+ this.amount = amount;
+ this.date = date;
+ }
+
+ @Override public String toString() {
+ return "Transaction{" +
+ "amount=" + amount +
+ ", date=" + date +
+ '}';
+ }
+
+ @Override public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Transaction that = (Transaction) o;
+
+ if (amount != that.amount) {
+ return false;
+ }
+ return date != null ? date.equals(that.date) : that.date == null;
+ }
+ @Override public int hashCode() {
+ int result = amount;
+ result = 31 * result + (date != null ? date.hashCode() : 0);
+ return result;
}
}
@@ -14,6 +14,8 @@
@RunWith(MockitoJUnitRunner.class) public class BankAccountShouldShould {
+ private static final Date ANY_DATE = new Date();
+
@Mock TransactionRepository repository;
@Mock StatementFormatter formatter;
@Mock StatementView view;
@@ -33,7 +35,7 @@ private BankAccount givenAccountWithMockedClock() {
}
private Date date() {
- return new Date();
+ return ANY_DATE;
}
private BankAccount givenAccount() {

0 comments on commit 1f5cdab

Please sign in to comment.