Remove PowerMock from oauth2-core and oauth2-jose
Issue: gh-6025
This commit is contained in:
parent
9ee291e659
commit
2a8233d035
|
@ -21,6 +21,8 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest;
|
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest;
|
||||||
import org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient;
|
import org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient;
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
||||||
|
@ -34,12 +36,11 @@ import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationResp
|
||||||
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AccessTokenResponses;
|
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AccessTokenResponses;
|
||||||
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationRequests;
|
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationRequests;
|
||||||
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationResponses;
|
import org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationResponses;
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
|
|
@ -16,36 +16,32 @@
|
||||||
package org.springframework.security.oauth2.core.endpoint;
|
package org.springframework.security.oauth2.core.endpoint;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationRequests.request;
|
||||||
|
import static org.springframework.security.oauth2.core.endpoint.TestOAuth2AuthorizationResponses.success;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OAuth2AuthorizationExchange}.
|
* Tests for {@link OAuth2AuthorizationExchange}.
|
||||||
*
|
*
|
||||||
* @author Joe Grandja
|
* @author Joe Grandja
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({OAuth2AuthorizationExchange.class, OAuth2AuthorizationRequest.class, OAuth2AuthorizationResponse.class})
|
|
||||||
public class OAuth2AuthorizationExchangeTests {
|
public class OAuth2AuthorizationExchangeTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void constructorWhenAuthorizationRequestIsNullThenThrowIllegalArgumentException() {
|
public void constructorWhenAuthorizationRequestIsNullThenThrowIllegalArgumentException() {
|
||||||
new OAuth2AuthorizationExchange(null, mock(OAuth2AuthorizationResponse.class));
|
new OAuth2AuthorizationExchange(null, success().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void constructorWhenAuthorizationResponseIsNullThenThrowIllegalArgumentException() {
|
public void constructorWhenAuthorizationResponseIsNullThenThrowIllegalArgumentException() {
|
||||||
new OAuth2AuthorizationExchange(mock(OAuth2AuthorizationRequest.class), null);
|
new OAuth2AuthorizationExchange(request().build(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorWhenRequiredArgsProvidedThenCreated() {
|
public void constructorWhenRequiredArgsProvidedThenCreated() {
|
||||||
OAuth2AuthorizationRequest authorizationRequest = mock(OAuth2AuthorizationRequest.class);
|
OAuth2AuthorizationRequest authorizationRequest = request().build();
|
||||||
OAuth2AuthorizationResponse authorizationResponse = mock(OAuth2AuthorizationResponse.class);
|
OAuth2AuthorizationResponse authorizationResponse = success().build();
|
||||||
OAuth2AuthorizationExchange authorizationExchange =
|
OAuth2AuthorizationExchange authorizationExchange =
|
||||||
new OAuth2AuthorizationExchange(authorizationRequest, authorizationResponse);
|
new OAuth2AuthorizationExchange(authorizationRequest, authorizationResponse);
|
||||||
assertThat(authorizationExchange.getAuthorizationRequest()).isEqualTo(authorizationRequest);
|
assertThat(authorizationExchange.getAuthorizationRequest()).isEqualTo(authorizationRequest);
|
||||||
|
|
|
@ -20,16 +20,10 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.nimbusds.jwt.JWTParser;
|
|
||||||
import okhttp3.mockwebserver.MockResponse;
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
import okhttp3.mockwebserver.MockWebServer;
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
import org.assertj.core.api.Assertions;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -48,9 +42,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.powermock.api.mockito.PowerMockito.spy;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link NimbusJwtDecoderJwkSupport}.
|
* Tests for {@link NimbusJwtDecoderJwkSupport}.
|
||||||
|
@ -58,9 +52,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
* @author Joe Grandja
|
* @author Joe Grandja
|
||||||
* @author Josh Cummings
|
* @author Josh Cummings
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({NimbusJwtDecoderJwkSupport.class, JWTParser.class})
|
|
||||||
@PowerMockIgnore("okhttp3.*")
|
|
||||||
public class NimbusJwtDecoderJwkSupportTests {
|
public class NimbusJwtDecoderJwkSupportTests {
|
||||||
private static final String JWK_SET_URL = "https://provider.com/oauth2/keys";
|
private static final String JWK_SET_URL = "https://provider.com/oauth2/keys";
|
||||||
private static final String JWS_ALGORITHM = JwsAlgorithms.RS256;
|
private static final String JWS_ALGORITHM = JwsAlgorithms.RS256;
|
||||||
|
@ -248,7 +239,7 @@ public class NimbusJwtDecoderJwkSupportTests {
|
||||||
|
|
||||||
private static RestOperations mockJwkSetResponse(String response) {
|
private static RestOperations mockJwkSetResponse(String response) {
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
Mockito.when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
when(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
||||||
.thenReturn(new ResponseEntity<>(response, HttpStatus.OK));
|
.thenReturn(new ResponseEntity<>(response, HttpStatus.OK));
|
||||||
return restOperations;
|
return restOperations;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue