### Question:
AuthenticationUtilService { public String getAuthenticatedProvider() throws NotAuthenticatedException { if (!isAuthenticatedUserOfType(AuthenticatedUserType.PROVIDER)) { throw new NotAuthenticatedException(AuthenticatedUserType.PROVIDER); } return httpRequest.getUserPrincipal().getName(); }  boolean isAuthenticatedUser(); Principal getAuthenticatedUserPrincipal(); boolean isUserInRole(String role); boolean isUserInAnyOfRoles(boolean acceptAdmin, String... roles); boolean isUserInAnyOfRoles(boolean acceptAdmin, Collection<String> roles); String getAuthenticatedProvider(); void checkProviderManagementPermission(String providerName); String getAuthenticatedContributor(boolean forceCreate); boolean updateAuthenticatedContributorProfile(); AuthenticatedUserType getAuthenticatedUserType(); Set<String> getUserRoles(); boolean isAuthenticatedUserOfType(AuthenticatedUserType userType);  }### Answer:
@Test public void getAuthenticatedProvider() { AuthenticationUtilService tested = getTested(); try { Mockito.reset(tested.contributorProfileService, tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(null); tested.getAuthenticatedProvider(); Assert.fail("NotAuthenticatedException expected"); } catch (NotAuthenticatedException e) { Mockito.verifyZeroInteractions(tested.contributorProfileService); } try { Mockito.reset(tested.contributorProfileService, tested.httpRequest); Principal p = new ContributorPrincipal("uname"); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(true); tested.getAuthenticatedProvider(); Assert.fail("NotAuthenticatedException expected"); } catch (NotAuthenticatedException e) { Mockito.verifyZeroInteractions(tested.contributorProfileService); } { Mockito.reset(tested.contributorProfileService, tested.httpRequest); Principal p = new ProviderPrincipal("uname"); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.PROVIDER)).thenReturn(true); Assert.assertEquals("uname", tested.getAuthenticatedProvider()); Mockito.verifyNoMoreInteractions(tested.contributorProfileService); } }