ServerUsernameProvider implements UsernameProvider { @Override public String get() { try { return sessionInfo.getIdentity().getIdentifier(); } catch (Exception e) { return "not-logged-user"; } } ServerUsernameProvider(); @Inject  ServerUsernameProvider(final SessionInfo sessionInfo); @Override String get();  }
@Test public void testLoggedUserName() { final String username = serverUsernameProvider.get(); verify(sessionInfo).getIdentity(); assertEquals(sessionInfo.getIdentity().getIdentifier(), username); }
@Test public void testNotLoggedUserName() { doThrow(new ContextNotActiveException()).when(sessionInfo).getIdentity(); final String username = serverUsernameProvider.get(); verify(sessionInfo).getIdentity(); assertEquals("not-logged-user", username); }