@@ -195,7 +195,7 @@ public void salvarCliente_emailInvalido_retorno400(String email) throws Exceptio
195195 @ ParameterizedTest
196196 @ NullAndEmptySource
197197 @ ValueSource (strings = {" " , "101089757er" , "101089757" , "25013569874965" })
198- @ DisplayName ("Returns 400, tries to save a client with an invalid." )
198+ @ DisplayName ("Returns 400, tries to save a client with an invalid CPF ." )
199199 public void salvarCliente_cpfInvalido_retornar400 (String cpf ) throws Exception {
200200 dto .setCpf (cpf );
201201
@@ -207,6 +207,25 @@ public void salvarCliente_cpfInvalido_retornar400(String cpf) throws Exception {
207207 verifyNoMoreInteractions (service );
208208 }
209209
210+ @ Test
211+ @ DisplayName ("Attempts to save a client in database with an existing e-mail address. Returns 409." )
212+ public void salvarCliente_existingEmail_returns409 () throws Exception {
213+ ClienteRequestDTO dto1 = new ClienteRequestDTO ();
214+ dto1 .setNome ("Diego" );
215+ dto1 .setCpf ("52639854712" );
216+ dto1 .setEmail ("marcus@gmail.com" );
217+
218+ when (service .salvarCliente (any (ClienteRequestDTO .class )))
219+ .thenThrow (new EmailJaCadastradoException ());
220+
221+ mvc .perform (post ("/salvarcliente" ).contentType (MediaType .APPLICATION_JSON )
222+ .content (mapper .writeValueAsString (dto1 ))).andExpect (status ().isConflict ())
223+ .andExpect (content ().string ("E-mail indisponível, já está sendo utilizado." ));
224+
225+ verify (service ).salvarCliente (any (ClienteRequestDTO .class ));
226+ verifyNoMoreInteractions (service );
227+ }
228+
210229 @ Test
211230 @ DisplayName ("Returns 409, tries to save a client with an existing CPF." )
212231 public void salvarCliente_cpfExistente_retornar409 () throws Exception {
0 commit comments