Estou com um problema quando tento executar o código abaixo com o retorno de 400, porem o mesmo gera erro, mas quando faço com o 403, o mesmo retorna, alguém pode me ajudar?
package br.com.alura.forum.controller;
import java.net.URI;
import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("test") public class AutenticacaoControllerTest {
@Autowired
private MockMvc mockMvc; // Essa classe simula uma requisição mvc.
@Test
public void deveriaDevolver400CasoDadosDeAutenticacaoEstejamIncorretos() throws Exception {
URI uri = new URI("/auth");
String json = "{\"email\":\"invalido@email.com\",\"senha\":\"123465\"}";
mockMvc
.perform(MockMvcRequestBuilders
.post(uri)
.content(json)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers
.status()
.is(400));
}
}