### Question:
AuthenticationUtilService { public boolean updateAuthenticatedContributorProfile() { if (isAuthenticatedUserOfType(AuthenticatedUserType.CONTRIBUTOR)) { try { String username = SearchUtils.trimToNull(httpRequest.getUserPrincipal().getName()); if (username != null) { contributorProfileService.createOrUpdateProfile( mapPrincipalToContributorCodeType(httpRequest.getUserPrincipal()), username, false); return true; } } catch (Exception e) { log.log(Level.WARNING, "Contributor profile update failed: " + e.getMessage(), e); } } 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 updateAuthenticatedContributorProfile() { AuthenticationUtilService tested = getTested(); { Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(null); Assert.assertFalse(tested.updateAuthenticatedContributorProfile()); Mockito.verifyZeroInteractions(tested.contributorProfileService); } Principal p = Mockito.mock(Principal.class); { Mockito.reset(tested.contributorProfileService, tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.PROVIDER)).thenReturn(true); Assert.assertFalse(tested.updateAuthenticatedContributorProfile()); Mockito.verifyZeroInteractions(tested.contributorProfileService); } { Mockito.reset(tested.contributorProfileService, tested.httpRequest, p); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(true); Assert.assertFalse(tested.updateAuthenticatedContributorProfile()); Mockito.verifyZeroInteractions(tested.contributorProfileService); Mockito.verify(p).getName(); } { p = new ContributorPrincipal("uname"); Mockito.reset(tested.contributorProfileService, tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(true); Assert.assertTrue(tested.updateAuthenticatedContributorProfile()); Mockito.verify(tested.contributorProfileService).createOrUpdateProfile( ContributorProfileService.FIELD_TSC_JBOSSORG_USERNAME, "uname", false); Mockito.verifyNoMoreInteractions(tested.contributorProfileService); } { p = Mockito.mock(Principal.class); Mockito.reset(tested.contributorProfileService, tested.httpRequest); Mockito.when(tested.httpRequest.getUserPrincipal()).thenReturn(p); Mockito.when(tested.httpRequest.isUserInRole(Role.CONTRIBUTOR)).thenReturn(true); Assert.assertFalse(tested.updateAuthenticatedContributorProfile()); Mockito.verifyNoMoreInteractions(tested.contributorProfileService); } }