File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed
src/test/java/com/sistemaclliente Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -689,11 +689,32 @@ public void atualizarEmail_invalidEmail_returns400(String email) throws Exceptio
689689 }
690690
691691 @ Test @ DisplayName ("Attempts to find the client to update his email and finds none. Returns 400." )
692- public void atualizarEmail_naoEncontrado_retorno404 () throws Exception {
692+ public void atualizarEmail_clientNotFound_returns404 () throws Exception {
693693 mvc .perform (patch ("/atualizaremail/999" ).param ("email" , "marcus@gmail.com" ))
694694 .andExpect (status ().isNotFound ()).andExpect (content ().string (containsString ("não encontrado" )));
695695 }
696696
697+ @ Test @ Transactional @ DisplayName ("Attempts to update a client's email with an existing email address."
698+ + "Returns 409." )
699+ public void atualizarEmail_existingEmail_returns409 () throws Exception {
700+ Cliente cliente1 = new Cliente ();
701+ cliente1 .setNome ("Marcus" );
702+ cliente1 .setCpf ("23501206586" );
703+ cliente1 .setEmail ("marcus@gmail.com" );
704+
705+ Cliente cliente2 = new Cliente ();
706+ cliente2 .setNome ("Antonio" );
707+ cliente2 .setCpf ("20219064674" );
708+ cliente2 .setEmail ("antonio@gmail.com" );
709+
710+ repository .saveAndFlush (cliente1 );
711+ repository .saveAndFlush (cliente2 );
712+
713+ mvc .perform (patch ("/atualizaremail/" +cliente1 .getId ()).param ("email" , "antonio@gmail.com" ))
714+ .andExpect (status ().isConflict ()).andExpect (content ().string (containsString ("indisponível" )));
715+
716+ }
717+
697718}
698719
699720
Original file line number Diff line number Diff line change @@ -964,14 +964,14 @@ public void atualizarEmail_verboIncorreto_retorno405() throws Exception{
964964 verifyNoMoreInteractions (service );
965965 }
966966
967- @ Test
967+ @ Test @ DisplayName ( "Attempts to update a client's email with an existing email address. Returns 409." )
968968 public void atualizarEmail_emailExistente_retorno409 () throws Exception {
969- when (service .atualizarEmail (1L , "marcus @gmail.com" )).thenThrow (new EmailJaCadastradoException ());
969+ when (service .atualizarEmail (1L , "antonio @gmail.com" )).thenThrow (new EmailJaCadastradoException ());
970970
971- mvc .perform (patch ("/atualizaremail/1" ).param ("email" , "marcus @gmail.com" ))
971+ mvc .perform (patch ("/atualizaremail/1" ).param ("email" , "antonio @gmail.com" ))
972972 .andExpect (status ().isConflict ()).andExpect (content ().string (containsString ("indisponível" )));
973973
974- verify (service ).atualizarEmail (1L , "marcus @gmail.com" );
974+ verify (service ).atualizarEmail (1L , "antonio @gmail.com" );
975975 verifyNoMoreInteractions (service );
976976 }
977977
You can’t perform that action at this time.
0 commit comments