@Test
public void authenticateShouldReturnUserWhenAlreadyExists() throws AlpineAuthenticationException {

    wireMockRule.stubFor(get(urlPathEqualTo(OIDC_USERINFO_PATH))
            .willReturn(aResponse()
                    .withStatus(HttpStatus.SC_OK)
                    .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType())
                    .withBody("" +
                            "{" +
                            "    \"sub\": \"subject\", " +
                            "    \"email\": \"subject@mail.local\", " +
                            "    \"" + USERNAMCE_CLAIM + "\": \"username\"" +
                            "}")));
    final OidcAuthenticationService authService = new OidcAuthenticationService(configMock, oidcConfigurationMock, ACCESS_TOKEN);
    OidcUser existingUser;
    try (final AlpineQueryManager qm = new AlpineQueryManager()) {
        existingUser = new OidcUser();
        existingUser.setUsername("username");
        existingUser.setSubjectIdentifier("subject");
        existingUser.setEmail("subject@mail.local");
        existingUser = qm.persist(existingUser);
    }
    final OidcUser authenticatedUser = (OidcUser) authService.authenticate();
    assertThat(authenticatedUser).isNotNull();
    assertThat(authenticatedUser.getId()).isEqualTo(existingUser.getId());
    assertThat(authenticatedUser.getUsername()).isEqualTo(existingUser.getUsername());
    assertThat(authenticatedUser.getSubjectIdentifier()).isEqualTo(existingUser.getSubjectIdentifier());
    assertThat(authenticatedUser.getEmail()).isEqualTo(existingUser.getEmail());
    assertThat(authenticatedUser.getTeams()).isNullOrEmpty();
    assertThat(authenticatedUser.getPermissions()).isNullOrEmpty();
}