2525import br .com .developers .domain .repository .UserRepository ;
2626import br .com .developers .exception .ExistingEmailException ;
2727import br .com .developers .exception .IllegalRoleException ;
28+ import br .com .developers .exception .UserNotFoundException ;
2829import br .com .developers .login .dto .LoginDTO ;
2930import br .com .developers .login .dto .RegisterDTO ;
3031import br .com .developers .provider .LoginDTOProviderTest ;
@@ -120,7 +121,7 @@ void shouldUpdateUser(RegisterDTO registerData) {
120121 .willReturn (Optional .of (this .role ));
121122 BDDMockito .given (this .userRepository .save (this .user )).willReturn (this .user );
122123
123- User user = this .service .updateUser (registerData );
124+ User user = this .service .update (registerData );
124125
125126 assertEquals (registerData .getName (), user .getFirstName ());
126127 assertEquals (registerData .getLastName (), user .getLastName ());
@@ -130,6 +131,42 @@ void shouldUpdateUser(RegisterDTO registerData) {
130131 verify (this .roleRepository , times (1 )).findByName (any ());
131132 }
132133
134+ @ ParameterizedTest
135+ @ ArgumentsSource (RegisterDTOProviderTests .class )
136+ void shouldTryUpdateAndReturnUserNotFoundException (RegisterDTO registerData ) {
137+ BDDMockito .given (this .userRepository .findByEmail (registerData .getEmail ().toLowerCase ()))
138+ .willReturn (Optional .empty ());
139+
140+ Exception exception = assertThrows (Exception .class , () -> {
141+ this .service .update (registerData );
142+ });
143+
144+ assertTrue (exception instanceof UserNotFoundException );
145+ assertEquals (
146+ "Fail! -> Cause: User not found with email [" + registerData .getEmail ().toLowerCase () + "]" ,
147+ exception .getMessage ());
148+
149+ verify (this .userRepository , times (1 )).findByEmail (anyString ());
150+ }
151+
152+ @ ParameterizedTest
153+ @ ArgumentsSource (LoginDTOProviderTest .class )
154+ void shouldTryDeleteAndReturnUserNotFoundException (LoginDTO loginDTO ) {
155+ BDDMockito .given (this .userRepository .findByEmail (loginDTO .getEmail ().toLowerCase ()))
156+ .willReturn (Optional .empty ());
157+
158+ Exception exception = assertThrows (Exception .class , () -> {
159+ this .service .delete (loginDTO );
160+ });
161+
162+ assertTrue (exception instanceof UserNotFoundException );
163+ assertEquals (
164+ "Fail! -> Cause: User not found with email [" + loginDTO .getEmail ().toLowerCase () + "]" ,
165+ exception .getMessage ());
166+
167+ verify (this .userRepository , times (1 )).findByEmail (anyString ());
168+ }
169+
133170 @ ParameterizedTest
134171 @ ArgumentsSource (LoginDTOProviderTest .class )
135172 void shouldDeleteUser (LoginDTO loginDTO ) {
0 commit comments