原创

测试时无法从异常中获取消息[关闭]

温馨提示:
本文最后更新于 2024年04月12日,已超过 48 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我
@SpringBootTest
@AutoConfigureMockMvc
@Transactional
public class BankDemoBootApplicationIT {

    @Autowired
    private MockMvc mockMVC;
    private static final String PHONE = "0000000000";

    @Test
    void wrong_user_creds() throws Exception {
        
        mockMVC.perform(formLogin("/auth").user("phone", PHONE).password("localadmin"))
            .andExpect(status().is3xxRedirection())
            .andExpect(redirectedUrl("/login?error=true"))
            .andExpect(result -> assertThat
                (result.getResolvedException() instanceof BadCredentialsException))
            .andExpect(result -> assertEquals
                ("Bad Credentials", result.getResolvedException().getMessage()));
    }
}

I wonder why last andExpect(result -> assertEquals("Bad Credentials", result.getResolvedException().getMessage()) produces NullPointerException? When I perform login manually web-form succesfully recieves it at [[${session.SPRING_SECURITY_LAST_EXCEPTION.message}]]

正文到此结束
热门推荐
本文目录