SecurityContextUtil { public static SecurityContext getSC() { return SecurityContextUtil.getContext().getSecurityContext(); }  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 getSCWithNullInstance() throws Exception { MessageContext messageContext = PowerMockito.mock(MessageContext.class); PowerMockito.when(messageContext.getSecurityContext()).thenReturn(null); PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(messageContext).when(SecurityContextUtil.class, "getContext"); Assert.assertNull(SecurityContextUtil.getSC()); }
@Test public void getSCWithValidInstance() throws Exception { SecurityContext securityContext = PowerMockito.mock(SecurityContext.class); MessageContext messageContext = PowerMockito.mock(MessageContext.class); PowerMockito.when(messageContext.getSecurityContext()).thenReturn(securityContext); PowerMockito.spy(SecurityContextUtil.class); PowerMockito.doReturn(messageContext).when(SecurityContextUtil.class, "getContext"); Assert.assertEquals(securityContext, SecurityContextUtil.getSC()); }