assertFalse(service.isUserAdmin());
}
/** Test getCurrentUser(). */
@Test public void testGetCurrentUser() {
User user = new User("email", "google.com", "userId", "federatedIdentity");
UserService userService = mock(UserService.class);
SpringContextService springContextService = mock(SpringContextService.class);
GaeUserService service = new GaeUserService();
service.setUserService(userService);
service.setSpringContextService(springContextService);
service.afterPropertiesSet();
when(userService.isUserLoggedIn()).thenReturn(false);
FederatedUser currentUser = service.getCurrentUser();
assertNull(currentUser);
when(userService.isUserLoggedIn()).thenReturn(true);
when(userService.getCurrentUser()).thenReturn(user);
when(userService.isUserAdmin()).thenReturn(true);
currentUser = service.getCurrentUser();
assertEquals(user.getEmail(), currentUser.getEmailAddress());
assertEquals(user.getAuthDomain(), currentUser.getAuthenticationDomain());
assertEquals(OpenIdProvider.GOOGLE, currentUser.getOpenIdProvider()); // because auth domain is "google.com"
assertEquals(user.getUserId(), currentUser.getUserId());
assertEquals(user.getFederatedIdentity(), currentUser.getFederatedIdentity());
assertTrue(currentUser.isAdmin());
when(userService.isUserLoggedIn()).thenReturn(true);
when(userService.getCurrentUser()).thenReturn(user);
when(userService.isUserAdmin()).thenReturn(false);
currentUser = service.getCurrentUser();
assertEquals(user.getEmail(), currentUser.getEmailAddress());
assertEquals(user.getAuthDomain(), currentUser.getAuthenticationDomain());
assertEquals(OpenIdProvider.GOOGLE, currentUser.getOpenIdProvider()); // because auth domain is "google.com"
assertEquals(user.getUserId(), currentUser.getUserId());
assertEquals(user.getFederatedIdentity(), currentUser.getFederatedIdentity());
assertFalse(currentUser.isAdmin());
}