Browse Source

Added: Better Test Coverage for the Birthday class

feature-pr/user
Maxim Volkov 3 years ago
parent
commit
66a8e380b0
  1. 6
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java
  2. 19
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java

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

@ -43,13 +43,13 @@ public class Birthdate {
}
public boolean isValid(int DD, int MM, int YYYY) {
if (DD < 1) {
if (DD < 1 || DD > 31) {
return false;
}
if (MM < 1) {
if (MM < 1 || MM > 12) {
return false;
}
if (YYYY < 1) {
if (YYYY < 1990 || YYYY > 2022) {
return false;
}

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

@ -39,6 +39,25 @@ public class BirthdateTest extends TestCase {
boolean expectedResult = false;
boolean gotResult = birthdate.isValid(0, 0, 0);
assertEquals(expectedResult, gotResult);
gotResult = birthdate.isValid(32, 13, 1990);
assertEquals(expectedResult, gotResult);
gotResult = birthdate.isValid(31, 0, 1980);
assertEquals(expectedResult, gotResult);
gotResult = birthdate.isValid(31, 13, 1980);
assertEquals(expectedResult, gotResult);
gotResult = birthdate.isValid(1, 1, 3000);
assertEquals(expectedResult, gotResult);
gotResult = birthdate.isValid(1, 1, 1900);
assertEquals(expectedResult, gotResult);
expectedResult = true;
gotResult = birthdate.isValid(1, 5, 2020);
assertEquals(expectedResult, gotResult);
}
}
Loading…
Cancel
Save