public void testGetAppList(){
//当调用认证方法则抛出异常信息。模拟测试数据。
AuthenticationManager authenticationManager = Mockito.mock(AuthenticationManager.class);
UserLoggedStatusStore userLoggedStatusStore = Mockito.mock(UserLoggedStatusStore.class);
AppService appService = Mockito.mock(AppService.class);
this.ki4soService.setAuthenticationManager(authenticationManager);
this.ki4soService.setUserLoggedStatusStore(userLoggedStatusStore);
this.ki4soService.setAppService(appService);
/**
* 测试传递错误参数的情况。
*/
Assert.assertEquals(0, this.ki4soService.getAppList(null).size());
/**
* 测试正确参数的情况。
*/
Credential credential = Mockito.mock(Credential.class);
Assert.assertEquals(0, this.ki4soService.getAppList(credential).size());
/**
* 测试正确参数,但是返回值的属principal为空的情况。
*/
credential = Mockito.mock(Credential.class);
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authenticationManager.authenticate(credential)).thenReturn(authentication);
Assert.assertEquals(0, this.ki4soService.getAppList(credential).size());
/**
* 测试正确参数,但是返回值的属principal不是空的情况。
*/
credential = Mockito.mock(Credential.class);
authentication = Mockito.mock(Authentication.class);
Mockito.when(authenticationManager.authenticate(credential)).thenReturn(authentication);
Mockito.when(authentication.getPrincipal()).thenReturn(Mockito.mock(Principal.class));
List<UserLoggedStatus> list = new ArrayList<UserLoggedStatus>();
UserLoggedStatus loggedStatus = new UserLoggedStatus("test", "1001");
list.add(loggedStatus);
Mockito.when(userLoggedStatusStore.findUserLoggedStatus(Mockito.anyString())).thenReturn(list);
App app = new App();
Mockito.when(appService.findAppById(Mockito.anyString())).thenReturn(app);
Assert.assertEquals(1, this.ki4soService.getAppList(credential).size());
}