Browse Source

account details email address validation

feature-pr-Person
Sona Markosyan 3 years ago
parent
commit
9a14186457
  1. 7
      src/main/java/hs/fulda/de/ci/exam/project/Account.java
  2. 1
      src/main/java/hs/fulda/de/ci/exam/project/Person.java
  3. 39
      src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java

7
src/main/java/hs/fulda/de/ci/exam/project/Account.java

@ -59,14 +59,11 @@ public class Account {
person.validatePhoneNumber();
}
public boolean addAccountDetails(String name, Address address, String email, String phone){
public void addAccountDetails(String name, Address address, String email, String phone){
Person person = new Person(name, address, email, phone);
validatePersonDetails(person);
if(accountRepository.addPersonalDetails(person)){
return true;
};
return false;
accountRepository.addPersonalDetails(person);
}
}

1
src/main/java/hs/fulda/de/ci/exam/project/Person.java

@ -48,7 +48,6 @@ public class Person {
if(!matcher.matches()){
throw new RuntimeException("Email address is not Valid");
}
}
public void validatePhoneNumber(){

39
src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java

@ -56,16 +56,53 @@ public class AccountTest {
});
}
@Test
@DisplayName("Should Not add Account details when Address is null")
public void shouldThrowRuntimeExceptionWhenAddressIsNull(){
assertThrows(RuntimeException.class, () -> {
account1.addAccountDetails("John", null,"max.mustermann@gmail.com", "0151283290" );
});
}
@DisplayName("Check if the Email is valid")
@ParameterizedTest
@MethodSource("phoneNumberList")
public void shouldThrowRuntimeExceptionWhenPhoneNumberIsNull(String phoneNumber){
assertThrows(RuntimeException.class, () -> {
account1.addAccountDetails(null, address1,"max.mustermann@gmail.com", phoneNumber);
account1.addAccountDetails("John", address1,"max.mustermann@gmail.com", phoneNumber);
});
}
private static List<String> phoneNumberList() {
return Arrays.asList("1234567", "0123", "0125314622696456", "0abnajf");
}
@Test
@DisplayName("Should Not add Account details when Email is blank")
public void shouldThrowRuntimeExceptionWhenEmailIsNull(){
assertThrows(RuntimeException.class, () -> {
account1.addAccountDetails("John", address1," ", "0151283290" );
});
assertThrows(RuntimeException.class, () -> {
account1.addAccountDetails("John", address1,null, "0151283290" );
});
}
@ParameterizedTest
@MethodSource("EmailList")
@DisplayName("Should Not add Account details when Email Address is not valid")
public void shouldThrowRuntimeExceptionWhenEmailIsInvalid(String email){
try{
account1.addAccountDetails("John", address1, email, "0151283290");
}
catch(final RuntimeException e){
String msg2 = "Email address is not Valid";
assertEquals(msg2, e.getMessage());
}
}
private static List<String> EmailList() {
return Arrays.asList("max.musterman", "12245.com");
}
}
Loading…
Cancel
Save