AbstractService { protected final User getCurrentUser() { OAuthToken t = (OAuthToken) securityContext.getUserPrincipal(); if (t.getIdentity() != null) { return t.getIdentity().getUser(); } return null; }  final InjectionManager getInjector(); final void setInjector(final InjectionManager injector); final UriInfo getUriInfo(); final void setUriInfo(final UriInfo uriInfo); final Session getSession(); final void setSession(final Session session); final SearchFactory getSearchFactory(); final void setSearchFactory(final SearchFactory searchFactory); final FullTextSession getFullTextSession(); final void setFullTextSession(
            final FullTextSession fullTextSession); final Configuration getConfig(); final void setConfig(final Configuration config); final SecurityContext getSecurityContext(); final void setSecurityContext(
            final SecurityContext securityContext);  }
@Test public void testGetCurrentUser() { ApplicationContext adminContext = getAdminContext().getBuilder() .bearerToken() .build(); Mockito.doReturn(getAdminContext().getToken()) .when(mockContext).getUserPrincipal(); User user = service.getCurrentUser(); assertNotNull(user); assertEquals(adminContext.getToken().getIdentity().getUser(), user); }
@Test public void testGetCurrentUserClientCredentials() { ApplicationContext adminContext = getAdminContext().getBuilder() .client(ClientType.ClientCredentials) .bearerToken() .build(); Mockito.doReturn(adminContext.getToken()) .when(mockContext).getUserPrincipal(); assertNull(service.getCurrentUser()); }