### Question:
SelfResourceImpl implements SelfResource { @Override public Response getSelf(AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes) { try { String internalId = getInternalId(); return userResource.getById(internalId, attributes, excludedAttributes); } catch (UnableToResolveIdException e) { return createErrorResponse(e); } catch (ScimException e) { return createErrorResponse(e); } }  @Override Response getSelf(AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response update(ScimUser resource, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response patch(PatchRequest patchRequest, AttributeReferenceListWrapper attributes, AttributeReferenceListWrapper excludedAttributes); @Override Response delete();  }### Answer:
@Test public void noSelfIdResolverTest() { Principal principal = mock(Principal.class); SessionContext sessionContext = mock(SessionContext.class); @SuppressWarnings("unchecked") Instance<SelfIdResolver> selfIdResolverInstance = mock(Instance.class); when(sessionContext.getCallerPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("test-user"); when(selfIdResolverInstance.isUnsatisfied()).thenReturn(true); SelfResourceImpl selfResource = new SelfResourceImpl(); selfResource.selfIdResolver = selfIdResolverInstance; selfResource.sessionContext = sessionContext; Response response = selfResource.getSelf(null, null); assertThat(response.getEntity(), instanceOf(ErrorResponse.class)); List<String> messages = ((ErrorResponse)response.getEntity()).getErrorMessageList(); assertThat(messages, hasItem("Caller SelfIdResolver not available")); assertThat(messages, hasSize(1)); }
@Test public void withSelfIdResolverTest() throws UnableToResolveIdException, ScimException { String internalId = "test-user-resolved"; Principal principal = mock(Principal.class); SessionContext sessionContext = mock(SessionContext.class); @SuppressWarnings("unchecked") Instance<SelfIdResolver> selfIdResolverInstance = mock(Instance.class); SelfIdResolver selfIdResolver = mock(SelfIdResolver.class); UserResource userResource = mock(UserResource.class); Response mockResponse = mock(Response.class); when(sessionContext.getCallerPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("test-user"); when(selfIdResolverInstance.isUnsatisfied()).thenReturn(false); when(selfIdResolverInstance.get()).thenReturn(selfIdResolver); when(selfIdResolver.resolveToInternalId(principal)).thenReturn(internalId); when(userResource.getById(internalId, null, null)).thenReturn(mockResponse); SelfResourceImpl selfResource = new SelfResourceImpl(); selfResource.selfIdResolver = selfIdResolverInstance; selfResource.sessionContext = sessionContext; selfResource.userResource = userResource; assertThat(selfResource.getSelf(null, null), sameInstance(mockResponse)); }