为具有getPrincipal()的方法编写测试用例

时间:2015-12-11 09:46:47

标签: testing junit

其实我刚开始写一个测试用例...请帮我写一个测试用例代码..

@RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
    public String homePage(Model uiModel) {
        logger.info("Home Page!");
        uiModel.addAttribute("greeting", getPrincipal().toLowerCase());
        return "home";
    }

private String getPrincipal(){
        String userName = null;
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        if (principal instanceof UserDetails) {
            userName = ((UserDetails)principal).getUsername();
        } else {
            userName = principal.toString();
        }
        return userName;
    }

0 个答案:

没有答案