Permalink
Browse files

Inner loop - Red: Test store transaction

  • Loading branch information...
1 parent 8ce1466 commit a1f87010508f0ea08e16cb8dda5b7789668ea8d8 @CarlosMChica committed May 2, 2016
@@ -0,0 +1,9 @@
+package me.panavtec.androidbankkata.account.transaction;
+
+import java.util.Date;
+
+public class Transaction {
+ public Transaction(int amount, Date date) {
+
+ }
+}
@@ -1,4 +1,7 @@
package me.panavtec.androidbankkata.account.transaction;
public class TransactionRepository {
+ public void store(Transaction transaction) {
+ throw new UnsupportedOperationException();
+ }
}
@@ -0,0 +1,56 @@
+package me.panavtec.androidbankkata.account;
+
+import java.util.Date;
+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;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.class) public class BankAccountShouldShould {
+
+ @Mock TransactionRepository repository;
+ @Mock StatementFormatter formatter;
+ @Mock StatementView view;
+ @Mock Clock clock;
+
+ @Test public void store_a_transaction() {
+ BankAccount account = givenAccountWithMockedClock();
+
+ account.deposit(anAmount());
+
+ verifyStore(aTransactionWith(anAmount()));
+ }
+
+ private BankAccount givenAccountWithMockedClock() {
+ when(clock.today()).thenReturn(date());
+ return givenAccount();
+ }
+
+ private Date date() {
+ return new Date();
+ }
+
+ private BankAccount givenAccount() {
+ BankAccount account = new BankAccount(repository, formatter, clock);
+ account.attach(view);
+ return account;
+ }
+
+ private int anAmount() {
+ return 100;
+ }
+
+ private Transaction aTransactionWith(int anyAmount) {
+ return new Transaction(anyAmount, date());
+ }
+
+ private void verifyStore(Transaction transaction) {
+ verify(repository).store(transaction);
+ }
+}

0 comments on commit a1f8701

Please sign in to comment.