1515import org .junit .jupiter .api .Test ;
1616import org .junit .jupiter .params .ParameterizedTest ;
1717import org .junit .jupiter .params .provider .CsvSource ;
18+ import org .junit .jupiter .params .provider .EmptySource ;
1819import org .junit .jupiter .params .provider .NullAndEmptySource ;
20+ import org .junit .jupiter .params .provider .NullSource ;
1921import org .junit .jupiter .params .provider .ValueSource ;
2022import org .springframework .beans .factory .annotation .Autowired ;
2123import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
2224import org .springframework .boot .test .context .SpringBootTest ;
25+ import org .springframework .context .annotation .Import ;
2326import org .springframework .http .MediaType ;
2427import org .springframework .test .context .ActiveProfiles ;
2528import org .springframework .test .web .servlet .MockMvc ;
2629
2730import com .fasterxml .jackson .databind .ObjectMapper ;
2831import com .sistemacliente .SistemaClientesJavaApplication ;
32+ import com .sistemacliente .exception .ValidationExceptionHandler ;
2933import com .sistemacliente .model .Cliente ;
3034import com .sistemacliente .model .dto .ClienteRequestDTO ;
31- import com .sistemacliente .model .dto .ClienteResponseDTO ;
3235import com .sistemacliente .repository .ClienteRepository ;
3336
3437import jakarta .transaction .Transactional ;
3538
3639@ SpringBootTest (classes = SistemaClientesJavaApplication .class )
3740@ AutoConfigureMockMvc
3841@ ActiveProfiles ("test" )
42+ @ Import (ValidationExceptionHandler .class )
3943public class ClienteControllerIntegrationTest {
4044
4145 @ Autowired
@@ -55,9 +59,7 @@ public void setup() {
5559 repository .deleteAll ();
5660 }
5761
58- @ Test
59- @ Transactional
60- @ DisplayName ("Returns 200 and a list of the clients from the database." )
62+ @ Test @ Transactional @ DisplayName ("Returns 200 and a list of the clients from the database." )
6163 public void listarClientes_fullList_return200 () throws Exception {
6264 Cliente cliente1 = new Cliente ();
6365 cliente1 .setNome ("Marcus" );
@@ -465,6 +467,17 @@ public void buscarPorNomePagina_invalidParameters_returns400(String nome, int pa
465467 .andExpect (status ().isBadRequest ())
466468 .andExpect (content ().string ("A página não pode ser negativa e itens não pode ser menor que 1." ));
467469 }
470+
471+ @ ParameterizedTest @ NullAndEmptySource @ ValueSource (strings = " " )
472+ @ DisplayName ("Returns 400. Invalid parameters (invalid name)." )
473+ public void buscarPorNomePagina_invalidName_returns400 (String nome ) throws Exception {
474+ mvc .perform (get ("/buscapornome?pagina=0&itens=2" ).param ("nome" , nome ))
475+ .andExpect (status ().isBadRequest ()).andExpect (content ()
476+ .string ("Nome para busca não pode ser vazio ou nulo." ));
477+ }
478+
479+
480+
468481}
469482
470483
0 commit comments