From 9a141864578332820124ca44ed81ef5c6dc61ffa Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Tue, 8 Feb 2022 22:54:25 +0100 Subject: [PATCH] account details email address validation --- .../hs/fulda/de/ci/exam/project/Account.java | 7 +--- .../hs/fulda/de/ci/exam/project/Person.java | 1 - .../fulda/de/ci/exam/project/AccountTest.java | 39 ++++++++++++++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Account.java b/src/main/java/hs/fulda/de/ci/exam/project/Account.java index ae0868a..c4c9007 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Account.java +++ b/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); } } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Person.java b/src/main/java/hs/fulda/de/ci/exam/project/Person.java index cb8f70c..f8aad64 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Person.java +++ b/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(){ diff --git a/src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java b/src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java index 0e2f4ec..5fef805 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/AccountTest.java +++ b/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 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 EmailList() { + return Arrays.asList("max.musterman", "12245.com"); + } }