一段有毒的代码

飞来飞去1 发布于 11/09 20:08
阅读 257
收藏 0
JDK

今天写的一个UT测试,测试结果有毒啊,大家帮忙看一看:

    @Test
    public void test5_removeHRset(){
        List<Object> ids = new ArrayList<Object>();
        ids.add(1);
        MultiValueMap<String, Object> map = new LinkedMultiValueMap();
        map.put("ids", ids);
        Map res = restTemplate.postForObject("/hrset/removeHRset", map, Map.class);
        System.out.println(res.containsKey(1));
        System.out.println(res.containsValue("删除成功!"));
        res.forEach((k,v)->{
            System.out.println(k+":"+v);
        });
        System.out.println(res.get(1));
        Assertions.assertThat(res.size()).isEqualTo(1);
        //Assertions.assertThat(res.get(1)).isEqualTo("删除成功!");
    }

下面是控制台打印的结果:

2018-11-09 19:59:05.528  INFO 78192 --- [o-auto-1-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-11-09 19:59:05.669 DEBUG 78192 --- [o-auto-1-exec-2] com.elex.oa.dao.hr.IHRsetDao.deleteOne   : ==>  Preparing: DELETE FROM tb_hr_set WHERE id=? 
2018-11-09 19:59:05.691 DEBUG 78192 --- [o-auto-1-exec-2] com.elex.oa.dao.hr.IHRsetDao.deleteOne   : ==> Parameters: 1(Integer)
2018-11-09 19:59:05.695 DEBUG 78192 --- [o-auto-1-exec-2] com.elex.oa.dao.hr.IHRsetDao.deleteOne   : <==    Updates: 1
false
true
1:删除成功!
null

 

加载中
1
RyuuKazu
RyuuKazu

key是String类型的"1"吧。。。

0
狼先生A
狼先生A

只是没抓到那个鬼,哈

0
飞来飞去1
飞来飞去1

虽然我在Controller和service层写的返回值是Map<Integer,String>,但是测试单元里的返回值Map的1改为字符串“1”,结果就对了,谢谢楼上了 

    @RequestMapping("/removeHRset")
    @ResponseBody
    public Map<Integer,String> removeHRset(
            @RequestParam("ids") List<Integer> ids
    ){
        return ihRsetService.removeMultiple(ids);
    }

测试结果: 

2018-11-12 09:23:01.796  INFO 46676 --- [o-auto-1-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-11-12 09:23:01.936 DEBUG 46676 --- [o-auto-1-exec-1] com.elex.oa.dao.hr.IHRsetDao.deleteOne   : ==>  Preparing: DELETE FROM tb_hr_set WHERE id=? 
2018-11-12 09:23:01.957 DEBUG 46676 --- [o-auto-1-exec-1] com.elex.oa.dao.hr.IHRsetDao.deleteOne   : ==> Parameters: 1(Integer)
2018-11-12 09:23:01.973 DEBUG 46676 --- [o-auto-1-exec-1] com.elex.oa.dao.hr.IHRsetDao.deleteOne   : <==    Updates: 1
true
true
1:删除成功!
删除成功!

 

返回顶部
顶部