itstack-demo-design-10-00 增加一个单测

作者: testggddkk创建于 2023年2月19日更新于 2023年2月19日

@Test public void helloTest() throws Exception {

MvcResult mvcResult = null;

mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/api/queryUserInfo?userId=1001")
        .accept(MediaType.APPLICATION_JSON))
        .andExpect(MockMvcResultMatchers.status().isOk())
        .andDo(MockMvcResultHandlers.print())
        .andReturn();
Assert.assertEquals("{\"code\":\"0000\",\"info\":\"success\",\"name\":\"虫虫:1001\",\"age\":19,\"address\":\"天津市南开区旮旯胡同100号\"}", mvcResult.getResponse().getContentAsString());

mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/api/queryUserInfo?userId=99999999")
        .accept(MediaType.APPLICATION_JSON))
        .andExpect(MockMvcResultMatchers.status().isOk())
        .andDo(MockMvcResultHandlers.print())
        .andReturn();
Assert.assertEquals("{\"code\":\"1111\",\"info\":\"非白名单可访问用户拦截!\",\"name\":null,\"age\":null,\"address\":null}", mvcResult.getResponse().getContentAsString());

}

内容来源: fuzhengwei/itstack-demo-design