Skip to content

Commit 4693426

Browse files
committed
Integration test: atualizarParcial, returs 400.
It tries to update client's name with a empty string and a null value.
1 parent 8eaafb3 commit 4693426

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/test/java/com/sistemaclliente/ClienteControllerIntegrationTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public void atualizarParcial_invalidIdUpdanting_returns400() throws Exception{
515515
.andExpect(content().string("O campo id não pode ser alterado."));
516516
}
517517

518-
@Test @Transactional
518+
@Test @Transactional @DisplayName("Returns 409 when it tries to update client's CPF.")
519519
public void atualizarParcial_invalidCpfUpdating_returns409() throws Exception{
520520
Cliente cliente1 = new Cliente();
521521
cliente1.setNome("Marcus");
@@ -530,6 +530,23 @@ public void atualizarParcial_invalidCpfUpdating_returns409() throws Exception{
530530
.content(mapper.writeValueAsString(updates))).andExpect(status().isConflict())
531531
.andExpect(content().string("Alteração de CPF não permitida."));
532532
}
533+
534+
@ParameterizedTest @NullAndEmptySource @ValueSource(strings = " ") @Transactional
535+
@DisplayName("It tries to update client's name with an empty string and a null value.")
536+
public void atualizarParcial_invalidName_returns400(String nome) throws Exception{
537+
Cliente cliente1 = new Cliente();
538+
cliente1.setNome("Marcus");
539+
cliente1.setCpf("23501206586");
540+
cliente1.setEmail("marcus@gmail.com");
541+
repository.saveAndFlush(cliente1);
542+
543+
Map<String, Object> updates = new HashMap<>();
544+
updates.put("nome", nome);
545+
546+
mvc.perform(patch("/parcial/"+cliente1.getId()).contentType(MediaType.APPLICATION_JSON)
547+
.content(mapper.writeValueAsString(updates))).andExpect(status().isBadRequest())
548+
.andExpect(content().string("Nome não pode ser vazio ou nulo."));
549+
}
533550

534551
}
535552

src/test/java/com/sistemaclliente/ClienteControllerTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ public void atualizarParcial_presencaDoId_retorno400() throws Exception{
736736
}
737737

738738

739-
@Test
739+
@Test @DisplayName("Returns 409 when it tries to update client's CPF.")
740740
public void atualizarParcial_presencaDoCpf_retorno409() throws Exception{
741741
Map<String, Object> updates = new HashMap<>();
742742
updates.put("cpf", "23501206586");
@@ -751,9 +751,8 @@ public void atualizarParcial_presencaDoCpf_retorno409() throws Exception{
751751
verifyNoMoreInteractions(service);
752752
}
753753

754-
@ParameterizedTest
755-
@NullAndEmptySource
756-
@ValueSource(strings = " ")
754+
@ParameterizedTest @NullAndEmptySource @ValueSource(strings = " ")
755+
@DisplayName("It tries to update client's name with a empty string and a null value.")
757756
public void atualizarParcial_nomeNuloVazio_retorno400(String nome) throws Exception{
758757
Map<String, Object> updates = new HashMap<>();
759758
updates.put("nome", nome);

0 commit comments

Comments
 (0)