SecurityContextUtil { public static boolean isLoggedIn() { return SecurityContextUtil.getUser() != null; }  static SecurityContext getSC(); static void assertSC(); static void assertLoggedIn(); static String getUser(); static IUser getUserObject(); static boolean hasRole(String role); static String requestId(); static boolean isLoggedIn();  }
@Test public void isLoggedInWithNullContext() throws Exception { PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(null).when(SecurityContextUtil.class, "getSC"); Assert.assertFalse(SecurityContextUtil.isLoggedIn()); }
@Test public void isLoggedInWithNullPrincipal() throws Exception { SecurityContext securityContext = PowerMockito.mock(SecurityContext.class); PowerMockito.when(securityContext.getUserPrincipal()).thenReturn(null); PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(securityContext).when(SecurityContextUtil.class, "getSC"); Assert.assertFalse(SecurityContextUtil.isLoggedIn()); }
@Test public void isLoggedInWithSetPrincipal() throws Exception { SecurityContext securityContext = PowerMockito.mock(SecurityContext.class); PowerMockito.when(securityContext.getUserPrincipal()).thenReturn(new SimplePrincipal("foobar")); PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(securityContext).when(SecurityContextUtil.class, "getSC"); Assert.assertTrue(SecurityContextUtil.isLoggedIn()); }