@@ -98,7 +98,7 @@ public void salvarCliente_success_return201() throws Exception {
9898 @ ValueSource (strings = {" " , "ab" , "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz12345678901" })
9999 @ DisplayName ("Returns 400, tries to save a client with an invalid name. A name is invalid if it"
100100 +" is empty, null, have less then 3 characters or more then 60 characters." )
101- public void salvarCliente_invalidName_returns400 (String name ) throws JsonProcessingException , Exception {
101+ public void salvarCliente_invalidName_returns400 (String name ) throws Exception {
102102 ClienteRequestDTO dto = new ClienteRequestDTO ();
103103 dto .setNome (name );
104104 dto .setCpf ("23501206586" );
@@ -114,7 +114,7 @@ public void salvarCliente_invalidName_returns400(String name) throws JsonProcess
114114 @ NullAndEmptySource
115115 @ ValueSource (strings = {"com" , " " , "marcus@marcus@" })
116116 @ DisplayName ("Returns 400 when trying to save a client with an invalid email adress." )
117- public void salvarCliente_emailInvalido_retorno400 (String email ) throws Exception {
117+ public void salvarCliente_invalidEmail_retorno400 (String email ) throws Exception {
118118 ClienteRequestDTO dto = new ClienteRequestDTO ();
119119 dto .setNome ("Marcus" );
120120 dto .setCpf ("23501206586" );
@@ -125,6 +125,20 @@ public void salvarCliente_emailInvalido_retorno400(String email) throws Exceptio
125125 .andExpect (jsonPath ("$.email" ).value (containsString ("inválido" )));
126126 }
127127
128+ @ ParameterizedTest
129+ @ NullAndEmptySource
130+ @ ValueSource (strings = {" " , "101089757er" , "101089757" , "25013569874965" })
131+ @ DisplayName ("Returns 400, tries to save a client with an invalid." )
132+ public void salvarCliente_InvalidCpf_returns400 (String cpf ) throws Exception {
133+ ClienteRequestDTO dto = new ClienteRequestDTO ();
134+ dto .setNome ("Marcus" );
135+ dto .setCpf (cpf );
136+ dto .setEmail ("marcus@email.com" );
137+
138+ mvc .perform (post ("/salvarcliente" ).contentType (MediaType .APPLICATION_JSON )
139+ .content (mapper .writeValueAsString (dto ))).andExpect (status ().isBadRequest ())
140+ .andExpect (jsonPath ("$.cpf" ).value (containsString ("11 dígitos do CPF" )));
141+ }
128142
129143}
130144
0 commit comments