AbstractService { protected final <K extends AbstractAuthzEntity> K requireEntityInput( final Class<K> requestedType, final K entity) { K resolved = resolveEntityInput(requestedType, entity); if (resolved == null) { throw new EntityRequiredException(); } return resolved; }  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(expected = BadRequestException.class) public void testRequireEntityInputNullEntity() { service.requireEntityInput(Application.class, null); }
@Test(expected = BadRequestException.class) public void testRequireEntityInputNoIdEntity() { service.requireEntityInput(Application.class, new Application()); }
@Test public void testRequireValidEntity() { ApplicationContext adminContext = getAdminContext().getBuilder() .client(ClientType.Implicit) .authenticator(AuthenticatorType.Test) .bearerToken(Scope.APPLICATION) .build(); Mockito.doReturn(adminContext.getToken()) .when(mockContext).getUserPrincipal(); Mockito.doReturn(true).when(mockContext) .isUserInRole(Scope.APPLICATION_ADMIN); Application a = service.requireEntityInput(Application.class, userApp.getApplication()); assertEquals(userApp.getApplication(), a); }