Skip to content

Commit f9d697e

Browse files
committed
Integration test: salvarCliente, invalid email, 400.
1 parent d44dd90 commit f9d697e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public void salvarCliente_emailInvalido_retorno400(String email) throws Exceptio
195195
@ParameterizedTest
196196
@NullAndEmptySource
197197
@ValueSource(strings = {" ", "101089757er", "101089757", "25013569874965"})
198+
@DisplayName("Returns 400, tries to save a client with an invalid.")
198199
public void salvarCliente_cpfInvalido_retornar400(String cpf) throws Exception {
199200
dto.setCpf(cpf);
200201

0 commit comments

Comments
 (0)