Skip to content

Commit 29b8523

Browse files
committed
Integration test: buscarPorEmailOrdenada, finds none.
Attempts to search for a client by the given email, but finds none.
1 parent ed3894b commit 29b8523

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/main/java/com/sistemacliente/service/ClienteService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ public ClienteResponseDTO atualizarEmail(Long id, String email) {
240240
return new ClienteResponseDTO(clienteAtualizado);
241241
}
242242

243+
/*This method is only to improve my skills and to learn Java, because the email address is unique and
244+
*any search by email will return a single client. We won't have a page with two or more clients.*/
243245
public Page<ClienteResponseDTO>
244246
buscaEmailPaginadaOrdenada(String email, int pagina, int itens, String ordenadoPor){
245247

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ public void atualizarEmail_existingEmail_returns409() throws Exception{
714714
.andExpect(status().isConflict()).andExpect(content().string(containsString("indisponível")));
715715
}
716716

717+
/*Those tests below are only for training, because the email address is unique.*/
718+
717719
@Test @Transactional @DisplayName("Searches for the client by email and returns a Page with that "
718720
+ "client. Returns 200.")
719721
public void buscarPorEmailOrdenada_successFullPage_returns200() throws Exception {
@@ -744,6 +746,13 @@ public void buscarPorEmailOrdenada_successFullPage_returns200() throws Exception
744746
.andExpect(status().isOk()).andExpect(jsonPath("$.content[0].nome").value("Marcus"));
745747
}
746748

749+
@Test @DisplayName("Attempts to search for a client by the given email, but finds none.")
750+
public void buscarPorEmailOrdenada_sucessoPageVazia_retorno200() throws Exception {
751+
mvc.perform(get("/buscarporemail").param("email", "marcus@gmail.com")
752+
.param("pagina", "0").param("itens", "2").param("ordenadoPor", "id"))
753+
.andExpect(status().isOk()).andExpect(jsonPath("$.content.length()").value(0));
754+
}
755+
747756
}
748757

749758

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,8 @@ public void atualizarEmail_erroDeServidor_retorno500() throws Exception{
987987
verifyNoMoreInteractions(service);
988988
}
989989

990+
/*Those tests below are only for training, because the email address is unique.*/
991+
990992
@Test @DisplayName("Searches for the client by email and returns a Page with that client. "
991993
+ "Returns 200.")
992994
public void buscarPorEmailOrdenada_sucessoPageCheia_retorno200() throws Exception {
@@ -1005,7 +1007,7 @@ public void buscarPorEmailOrdenada_sucessoPageCheia_retorno200() throws Exceptio
10051007
verifyNoMoreInteractions(service);
10061008
}
10071009

1008-
@Test
1010+
@Test @DisplayName("Attempts to search for a client by the given email, but finds none.")
10091011
public void buscarPorEmailOrdenada_sucessoPageVazia_retorno200() throws Exception {
10101012
List<ClienteResponseDTO> lista = List.of();
10111013
Page<ClienteResponseDTO> page = new PageImpl<>(lista);

0 commit comments

Comments
 (0)