File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
src/test/java/com/sistemaclliente Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 33import static org .hamcrest .CoreMatchers .containsString ;
44import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
55import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
6+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
67import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
78import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
89
@@ -140,6 +141,24 @@ public void salvarCliente_InvalidCpf_returns400(String cpf) throws Exception {
140141 .andExpect (jsonPath ("$.cpf" ).value (containsString ("11 dígitos do CPF" )));
141142 }
142143
144+ @ Test
145+ @ DisplayName ("Returns 409, tries to save a client with an existing CPF." )
146+ public void salvarCliente_existingCPF_returns409 () throws Exception {
147+ Cliente cliente1 = new Cliente ();
148+ cliente1 .setNome ("Marcus" );
149+ cliente1 .setCpf ("23501206586" );
150+ cliente1 .setEmail ("marcus@gmail.com" );
151+ repository .saveAndFlush (cliente1 );
152+
153+ ClienteRequestDTO dto1 = new ClienteRequestDTO ();
154+ dto1 .setNome ("Carlos" );
155+ dto1 .setCpf ("23501206586" );
156+ dto1 .setEmail ("carlos@gmail.com" );
157+
158+ mvc .perform (post ("/salvarcliente" ).contentType (MediaType .APPLICATION_JSON )
159+ .content (mapper .writeValueAsString (dto1 ))).andExpect (status ().isConflict ())
160+ .andExpect (content ().string ("O CPF 23501206586 já está cadastrado." ));
161+ }
143162}
144163
145164
Original file line number Diff line number Diff line change @@ -208,6 +208,7 @@ public void salvarCliente_cpfInvalido_retornar400(String cpf) throws Exception {
208208 }
209209
210210 @ Test
211+ @ DisplayName ("Returns 409, tries to save a client with an existing CPF." )
211212 public void salvarCliente_cpfExistente_retornar409 () throws Exception {
212213 ClienteRequestDTO dto1 = new ClienteRequestDTO ();
213214 dto1 .setNome ("Carlos" );
You can’t perform that action at this time.
0 commit comments