diff --git a/src/test/java/honours/ing/banq/BoilerplateTest.java b/src/test/java/honours/ing/banq/BoilerplateTest.java index f2904ac..c4ef8b6 100644 --- a/src/test/java/honours/ing/banq/BoilerplateTest.java +++ b/src/test/java/honours/ing/banq/BoilerplateTest.java @@ -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 diff --git a/src/test/java/honours/ing/banq/card/CardServiceTest.java b/src/test/java/honours/ing/banq/card/CardServiceTest.java new file mode 100644 index 0000000..c48c784 --- /dev/null +++ b/src/test/java/honours/ing/banq/card/CardServiceTest.java @@ -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); + } + +} \ No newline at end of file