//准备数据
String authName = "foo";
User user = AccountData.getRandomUser();
Role role = AccountData.getRandomRole();
user.getRoleList().add(role);
Authority auth = new Authority();
auth.setName(authName);
role.getAuthorityList().add(auth);
//录制脚本
EasyMock.expect(mockAccountManager.findUserByLoginName(user.getLoginName())).andReturn(user);
control.replay();
//执行测试
UserDetails userDetails = userDetailService.loadUserByUsername(user.getLoginName());
//校验结果
assertEquals(user.getLoginName(), userDetails.getUsername());
assertEquals(user.getPassword(), userDetails.getPassword());
assertEquals(1, userDetails.getAuthorities().size());
assertEquals(new GrantedAuthorityImpl(auth.getPrefixedName()), userDetails.getAuthorities().iterator().next());
}