3 Commits

  1. 14
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java
  2. 2
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java
  3. 26
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java
  4. 2
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java
  5. 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;
}
public boolean isValid(int DD, int MM, int YYYY) {
if (DD < 1 || DD > 31) {
return false;
}
if (MM < 1 || MM > 12) {
return false;
}
if (YYYY < 1990 || YYYY > 2022) {
return false;
}
return true;
}
}

2
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java

@ -32,7 +32,7 @@ public class User {
public String getNickName() {
return nickName;
}
public String geteMail() {
public String getEMail() {
return eMail;
}
public Birthdate getBirthdate() {

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

@ -34,4 +34,30 @@ 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);
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);
}
}

2
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java

@ -146,7 +146,7 @@ public class CustomersTest extends TestCase {
boolean correctFirstName = "Mia".equals(gotUser.getFirstName());
boolean correctLastName = "Muster".equals(gotUser.getLastName());
boolean correctNickName = "harley".equals(gotUser.getNickName());
boolean correctEMail = "mia@muster.de".equals(gotUser.geteMail());
boolean correctEMail = "mia@muster.de".equals(gotUser.getEMail());
boolean correctBirthdate = birthdate.toString().equals(gotUser.birthdate.toString());
// Then

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