diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index f3d5b81..ab9af4c 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -41,5 +41,19 @@ public class Birthdate { month = m; year = y; } + + public boolean isValid(int DD, int MM, int YYYY) { + if (DD < 1) { + return false; + } + if (MM < 1) { + return false; + } + if (YYYY < 1) { + return false; + } + + return true; + } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java index 23de888..8b3ea01 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -34,4 +34,11 @@ public class BirthdateTest extends TestCase { assertEquals(2001, b.getYear()); } + public void test_rejectInvalidBirthday() { + Birthdate birthdate = new Birthdate(0, 0, 0); + boolean expectedResult = false; + boolean gotResult = birthdate.isValid(0, 0, 0); + assertEquals(expectedResult, gotResult); + } + } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java new file mode 100644 index 0000000..419153e --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java @@ -0,0 +1,20 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class UserTest extends TestCase { + public void test_initAndGetBirthdayOfUser() { + // Given + Customers customers = new Customers(); + String firstName = "Mia"; + String lastName = "Muster"; + String nickName = "harley"; + String eMail = "mia@muster.de"; + int DD = 30, MM = 12, YYYY = 1997; + String expectedBirthdate = new Birthdate(DD, MM, YYYY).toString(); + + User userToCheck = new User(firstName, lastName, nickName, eMail, new Birthdate(DD, MM, YYYY)); + String gotBirthdate = userToCheck.getBirthdate().toString(); + boolean gotExpectedBirthdayBack = gotBirthdate.equals(expectedBirthdate); + } +}