Browse Source

Added: Birthday Validation + Test

feature-pr/user
Maxim Volkov 3 years ago
parent
commit
b3833f62b8
  1. 14
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java
  2. 7
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java
  3. 20
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java

14
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java

@ -42,4 +42,18 @@ public class Birthdate {
year = y; 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;
}
} }

7
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java

@ -34,4 +34,11 @@ public class BirthdateTest extends TestCase {
assertEquals(2001, b.getYear()); 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);
}
} }

20
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);
}
}
Loading…
Cancel
Save