@Test
public void loadUserDetails_NullOrBlankPrincipalName_UsernameNotFoundException() {

    // JDK10 var needed :)
    GrantedAuthoritiesFromAssertionAttributesWithDefaultRolesUserDetailsService userDetailsService =
            new GrantedAuthoritiesFromAssertionAttributesWithDefaultRolesUserDetailsService(new String[] {"role"},
                    DEFAULT_ROLES);
    when(assertion.getPrincipal()).thenReturn(principal);
    when(principal.getName()).thenReturn(null);
    assertThatThrownBy(() -> userDetailsService.loadUserDetails(assertion))
            .isInstanceOf(UsernameNotFoundException.class);
    verify(assertion, times(1)).getPrincipal();
    verify(principal, times(1)).getName();
    reset(assertion, principal);
    when(assertion.getPrincipal()).thenReturn(principal);
    when(principal.getName()).thenReturn("");
    assertThatThrownBy(() -> userDetailsService.loadUserDetails(assertion))
            .isInstanceOf(UsernameNotFoundException.class);
    verify(assertion, times(1)).getPrincipal();
    verify(principal, times(1)).getName();
    reset(assertion, principal);
    when(assertion.getPrincipal()).thenReturn(principal);
    when(principal.getName()).thenReturn("    ");
    assertThatThrownBy(() -> userDetailsService.loadUserDetails(assertion))
            .isInstanceOf(UsernameNotFoundException.class);
    verify(assertion, times(1)).getPrincipal();
    verify(principal, times(1)).getName();
}