Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inner loop - Red: Test store transaction
- Loading branch information
1 parent
8ce1466
commit a1f8701
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
app/src/main/java/me/panavtec/androidbankkata/account/transaction/Transaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.panavtec.androidbankkata.account.transaction; | ||
|
||
import java.util.Date; | ||
|
||
public class Transaction { | ||
public Transaction(int amount, Date date) { | ||
|
||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/me/panavtec/androidbankkata/account/transaction/TransactionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
package me.panavtec.androidbankkata.account.transaction; | ||
|
||
public class TransactionRepository { | ||
public void store(Transaction transaction) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/test/java/me/panavtec/androidbankkata/account/BankAccountShouldShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |