### Question:
OAuthClient { public TokenDetails obtainTokenDetailsByRunOnBehalfOfUserCredentials(String username, String realm) { String password = oidcConfiguration.getRunOnBehalfOfUserPassword(username, realm); return obtainTokenDetailsByApplicationCredentials(username, password, realm); } @Autowired  OAuthClient(OidcConfiguration oidcConfiguration,
                       RealmService realmService,
                       PublicKeyCacheService publicKeyCacheService,
                       SecurityConfig config); TokenDetails obtainTokenDetailsByAuthorizationCode(String code, String redirectUrl); TokenDetails obtainTokenDetailsByRefreshToken(String refreshToken); TokenDetails obtainTokenDetailsByApplicationCredentials(); TokenDetails obtainTokenDetailsByRunOnBehalfOfUserCredentials(String username, String realm); TokenDetails obtainTokenDetailsByApplicationCredentials(String username, String password); TokenDetails obtainTokenDetailsByApplicationCredentials(String username, String password, String realm); TokenDetails generateTokenDetails(String accessToken, String refreshToken); AccessToken parseAccessToken(String accessToken, String realm); void setConfig(SecurityConfig config); void setRealmService(RealmService realmService);  }### Answer:
@Test void obtainTokenDetailsByRunOnBehalfOfUserCredentials() throws Exception { String username = "pupkin2"; String userPassword = "pupkin2-password"; String realm = "realm_sk"; when(oidcConfiguration.getRunOnBehalfOfUserPassword(username, realm)).thenReturn(userPassword); TokenDetails expectedTokenDetails = new TokenDetails(); doReturn(expectedTokenDetails).when(client).obtainTokenDetails(eq(realm), paramsCaptor.capture()); assertEquals(expectedTokenDetails, client.obtainTokenDetailsByRunOnBehalfOfUserCredentials(username, realm)); Map<String, String> params = convertParamsToMap(paramsCaptor.getValue()); assertThat(params.size(), is(5)); assertThat(params.get(OAuth2Constants.GRANT_TYPE), is(OAuth2Constants.PASSWORD)); assertThat(params.get(OAuth2Constants.USERNAME), is(username)); assertThat(params.get(OAuth2Constants.PASSWORD), is(userPassword)); assertThat(params.get(OAuth2Constants.CLIENT_ID), is(clientId)); assertThat(params.get(OAuth2Constants.CLIENT_SECRET), is(clientSecret)); }