UserServiceUserProvider implements UserProvider { @Override public FeatureUser getCurrentUser() { SimpleFeatureUser featureUser = null; User user = userService.getCurrentUser(); if (user != null) { featureUser = new SimpleFeatureUser(user.getUserId(), userService.isUserAdmin()); featureUser.setAttribute("email", user.getEmail()); featureUser.setAttribute("nickname", user.getNickname()); } return featureUser; } UserServiceUserProvider(UserService userService); @Override FeatureUser getCurrentUser();  }
@Test public void userIsNotLoggedIn() { helper.setEnvIsLoggedIn(false); FeatureUser user = userProvider.getCurrentUser(); assertNull(user); }
@Test public void userIsLoggedIn() { helper.setEnvIsLoggedIn(true) .setEnvEmail("user@togglz.org") .setEnvAuthDomain("togglz.org"); UserService userService = UserServiceFactory.getUserService(); FeatureUser user = userProvider.getCurrentUser(); assertFalse(user.isFeatureAdmin()); assertEquals(userService.getCurrentUser().getUserId(), user.getName()); assertEquals(userService.getCurrentUser().getEmail(), user.getAttribute("email")); assertEquals(userService.getCurrentUser().getNickname(), user.getAttribute("nickname")); }
@Test public void userIsLoggedInAsAdmin() { helper.setEnvIsLoggedIn(true) .setEnvIsAdmin(true) .setEnvEmail("admin@togglz.org") .setEnvAuthDomain("togglz.org"); UserService userService = UserServiceFactory.getUserService(); FeatureUser user = userProvider.getCurrentUser(); assertTrue(user.isFeatureAdmin()); assertEquals(userService.getCurrentUser().getUserId(), user.getName()); assertEquals(userService.getCurrentUser().getEmail(), user.getAttribute("email")); assertEquals(userService.getCurrentUser().getNickname(), user.getAttribute("nickname")); }