You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.8 KiB
108 lines
3.8 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import org.junit.jupiter.api.*;
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
import org.junit.jupiter.params.provider.ValueSource;
|
|
import org.mockito.InjectMocks;
|
|
import org.mockito.Mock;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.Mockito.doReturn;
|
|
import static org.mockito.Mockito.when;
|
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
public class AccountTest {
|
|
|
|
@BeforeAll
|
|
public void setupAll(){
|
|
System.out.println("Should Print Before All Tests");
|
|
}
|
|
Address address1;
|
|
Account account2;
|
|
Person person1;
|
|
Account account1;
|
|
|
|
@BeforeEach
|
|
public void setup() {
|
|
address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany");
|
|
account2 = new Account("453", "notactive", Account.AccountStatus.CANCELED);
|
|
person1 = new Person("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206");
|
|
account1 = new Account("123", "password", Account.AccountStatus.ACTIVE);
|
|
}
|
|
@Test
|
|
void test_resetPassword(){
|
|
|
|
account1.resetPassword("newpass");
|
|
account2.resetPassword("notgood");
|
|
|
|
assertEquals("newpass", account1.getPassword(),"Password successfully changed.");
|
|
assertEquals("notactive", account2.getPassword(),"Activate your account to change your password");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Should Not add Account details when Person Name is null")
|
|
public void shouldThrowRuntimeExceptionWhenPersonNameIsNull(){
|
|
assertThrows(RuntimeException.class, () -> {
|
|
account1.addAccountDetails("1",null, address1,"max.mustermann@gmail.com", "0151283290" );
|
|
});
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Should Not add Account details when Address is null")
|
|
public void shouldThrowRuntimeExceptionWhenPersonAddressIsNull(){
|
|
assertThrows(RuntimeException.class, () -> {
|
|
account1.addAccountDetails("1", "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("1","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("1", "John", address1," ", "0151283290" );
|
|
});
|
|
assertThrows(RuntimeException.class, () -> {
|
|
account1.addAccountDetails("1", "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("1","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");
|
|
}
|
|
}
|