Skip to content

Commit

Permalink
add tests for the newly implemented code for Extension 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreybakker committed Aug 3, 2017
1 parent c17082d commit 95b14b0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/test/java/honours/ing/banq/BoilerplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ public class BoilerplateTest {

@Before
public void setUp() throws Exception {
account1 = new AccountInfo(bankAccountService.openAccount("Jan", "Jansen", "J.", "1996-1-1",
"1234567890", "Klaverstraat 1", "0612345678", "janjansen@gmail.com", "jantje96",
"1234"), "jantje96", "1234");
account2 = new AccountInfo(bankAccountService.openAccount("Piet", "Pietersen", "p.p", "1998-8-8",
"012345789", "Huisstraat 1", "0607080910", "piet@gmail.com", "piet1", "1234"), "piet1", "1234");
account1 = new AccountInfo(
bankAccountService.openAccount(
"Jan", "Jansen", "J.", "1996-1-1",
"1234567890", "Klaverstraat 1", "0612345678",
"janjansen@gmail.com", "jantje96", "1234"),
"jantje96", "1234");
account2 = new AccountInfo(
bankAccountService.openAccount("Piet", "Pietersen", "p.p", "1998-8-8",
"012345789", "Huisstraat 1", "0607080910",
"piet@gmail.com", "piet1", "1234"),
"piet1", "1234");

account1.token = authService.getAuthToken("jantje96", "1234").getAuthToken();
account2.token = authService.getAuthToken("piet1", "1234").getAuthToken();

assertThat(infoService.getBalance(account1.token, account1.iBan).getBalance(), equalTo
(0d));
assertThat(infoService.getBalance(account2.token, account2.iBan).getBalance(), equalTo
(0d));
assertThat(infoService.getBalance(account1.token, account1.iBan).getBalance(), equalTo(0d));
assertThat(infoService.getBalance(account2.token, account2.iBan).getBalance(), equalTo(0d));
}

@After
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/honours/ing/banq/card/CardServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package honours.ing.banq.card;

import honours.ing.banq.BoilerplateTest;
import honours.ing.banq.auth.CardBlockedError;
import honours.ing.banq.auth.InvalidPINError;
import honours.ing.banq.transaction.TransactionService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.Assert.*;

/**
* @author jeffrey
* @since 3-8-17
*/
public class CardServiceTest extends BoilerplateTest {

@Autowired
private CardService service;

@Autowired
private TransactionService transactionService;

@Test(expected = CardBlockedError.class)
public void blockCard() throws Exception {
for (int i = 0; i < 3; i++) {
try {
transactionService.depositIntoAccount(account1.iBan, account1.cardNumber, "0000", 10.0);
} catch (InvalidPINError ignored) { }
}

transactionService.depositIntoAccount(account1.iBan, account1.cardNumber, account1.pin, 10.0);
}

@Test
public void unblockCard() throws Exception {
try {
blockCard();
} catch (CardBlockedError ignored) { }

service.unblockCard(account1.token, account1.iBan, account1.cardNumber);

// Now test if the card is usable again
transactionService.depositIntoAccount(account1.iBan, account1.cardNumber, account1.pin, 10.0);
}

}

0 comments on commit 95b14b0

Please sign in to comment.