|
10 | 10 | import static org.mockito.Mockito.verify; |
11 | 11 | import java.util.HashSet; |
12 | 12 | import java.util.Optional; |
| 13 | +import java.util.UUID; |
13 | 14 | import org.junit.jupiter.api.BeforeEach; |
14 | 15 | import org.junit.jupiter.params.ParameterizedTest; |
15 | 16 | import org.junit.jupiter.params.provider.ArgumentsSource; |
| 17 | +import org.junit.jupiter.params.provider.ValueSource; |
16 | 18 | import org.mockito.BDDMockito; |
17 | 19 | import org.springframework.security.authentication.AuthenticationManager; |
18 | 20 | import org.springframework.security.crypto.password.PasswordEncoder; |
|
28 | 30 | import br.com.developers.exception.UserNotFoundException; |
29 | 31 | import br.com.developers.login.dto.LoginDTO; |
30 | 32 | import br.com.developers.login.dto.RegisterDTO; |
| 33 | +import br.com.developers.login.dto.UserDTO; |
31 | 34 | import br.com.developers.provider.LoginDTOProviderTest; |
32 | 35 | import br.com.developers.provider.RegisterDTOProviderTests; |
33 | 36 |
|
@@ -167,6 +170,35 @@ void shouldTryDeleteAndReturnUserNotFoundException(LoginDTO loginDTO) { |
167 | 170 | verify(this.userRepository, times(1)).findByEmail(anyString()); |
168 | 171 | } |
169 | 172 |
|
| 173 | + @ParameterizedTest |
| 174 | + @ValueSource(strings = {"926c66c4-78f2-45c8-ae52-9c661d1ebb03"}) |
| 175 | + void shouldTryFindAndReturnUserNotFoundException(String id) { |
| 176 | + BDDMockito.given(this.userRepository.findById(UUID.fromString(id))) |
| 177 | + .willReturn(Optional.empty()); |
| 178 | + |
| 179 | + Exception exception = assertThrows(Exception.class, () -> { |
| 180 | + this.service.find(id); |
| 181 | + }); |
| 182 | + |
| 183 | + assertTrue(exception instanceof UserNotFoundException); |
| 184 | + assertEquals("Fail! -> Cause: User not found with id [" + id + "]", exception.getMessage()); |
| 185 | + |
| 186 | + verify(this.userRepository, times(1)).findById(any()); |
| 187 | + } |
| 188 | + |
| 189 | + @ParameterizedTest |
| 190 | + @ValueSource(strings = {"926c66c4-78f2-45c8-ae52-9c661d1ebb03"}) |
| 191 | + void shouldFind(String id) { |
| 192 | + BDDMockito.given(this.userRepository.findById(UUID.fromString(id))) |
| 193 | + .willReturn(Optional.of(this.user)); |
| 194 | + |
| 195 | + UserDTO dto = this.service.find(id); |
| 196 | + |
| 197 | + assertEquals(this.user.getFirstName(), dto.getName()); |
| 198 | + assertEquals(this.user.getEmail(), dto.getEmail()); |
| 199 | + verify(this.userRepository, times(1)).findById(any()); |
| 200 | + } |
| 201 | + |
170 | 202 | @ParameterizedTest |
171 | 203 | @ArgumentsSource(LoginDTOProviderTest.class) |
172 | 204 | void shouldDeleteUser(LoginDTO loginDTO) { |
|
0 commit comments