### Question:
AuthenticationUtilService { public boolean isAuthenticatedUserOfType(AuthenticatedUserType userType) { if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "Principal: {0}, role to check: {1}", new Object[] { httpRequest.getUserPrincipal(), userType }); } if (httpRequest.getUserPrincipal() == null) { return false; } if (userType != null) { switch (userType) { case PROVIDER: return httpRequest.isUserInRole(Role.PROVIDER); case CONTRIBUTOR: return httpRequest.isUserInRole(Role.CONTRIBUTOR); } } return false; }  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 isAuthenticatedUserOfType() { AuthenticationUtilService tested = getTested(); { Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(null); Assert.assertFalse(tested.isAuthenticatedUserOfType(AuthenticatedUserType.CONTRIBUTOR)); Assert.assertFalse(tested.isAuthenticatedUserOfType(AuthenticatedUserType.PROVIDER)); } Principal p = Mockito.mock(Principal.class); { Mockito.reset(tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.PROVIDER)).thenReturn(true); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(false); Assert.assertFalse(tested.isAuthenticatedUserOfType(AuthenticatedUserType.CONTRIBUTOR)); Assert.assertTrue(tested.isAuthenticatedUserOfType(AuthenticatedUserType.PROVIDER)); } { Mockito.reset(tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.PROVIDER)).thenReturn(false); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(true); Assert.assertTrue(tested.isAuthenticatedUserOfType(AuthenticatedUserType.CONTRIBUTOR)); Assert.assertFalse(tested.isAuthenticatedUserOfType(AuthenticatedUserType.PROVIDER)); } { Mockito.reset(tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.PROVIDER)).thenReturn(false); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(false); Assert.assertFalse(tested.isAuthenticatedUserOfType(AuthenticatedUserType.CONTRIBUTOR)); Assert.assertFalse(tested.isAuthenticatedUserOfType(AuthenticatedUserType.PROVIDER)); Assert.assertFalse(tested.isAuthenticatedUserOfType(null)); } }