From: Gustavo Martin Morcuende Date: Sun, 4 Dec 2016 15:18:39 +0000 (+0100) Subject: Test throws UnsupportedOperationException as expected. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=0c4181f9584d7af4108cfb31b41b95d87e1534fe;p=JavaForFun Test throws UnsupportedOperationException as expected. You should configure your IDE for throwing UnsupportedOperationException whenever it automatically creates a method. In this way, when running our unit tests we are able to find out what is not yet implemented. --- diff --git a/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java new file mode 100644 index 0000000..348f65f --- /dev/null +++ b/TDD/sandromancuso/bank/src/main/java/org/craftedsw/feature/Account.java @@ -0,0 +1,20 @@ +package org.craftedsw.feature; + +public class Account { + + public void deposit(int amount) { + // IDE configuration for always throwing this exception + // when automatically creating methods. + // In this way, when running our unit tests we are + // able to find out what is not yet implemented. + throw new UnsupportedOperationException(); + } + + public void withdraw(int amount) { + throw new UnsupportedOperationException(); + } + + public void printStatement() { + throw new UnsupportedOperationException(); + } +} diff --git a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java index e2c6f1c..d65b95a 100644 --- a/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java +++ b/TDD/sandromancuso/bank/src/test/java/org/craftedsw/feature/PrintStatementFeature.java @@ -2,6 +2,7 @@ package org.craftedsw.feature; import static org.mockito.Mockito.verify; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -11,10 +12,16 @@ import org.mockito.runners.MockitoJUnitRunner; public class PrintStatementFeature { @Mock private Console console; + private Account account; + + @Before + public void initialise() { + account = new Account(); + } @Test public void print_statement_containing_all_transactions() { - account.deposti(1000); + account.deposit(1000); // No negative value, instead we use the verb withdraw. // Semantics are very important in the code!!! account.withdraw(100);