Remove PowerMock from oauth2-core and oauth2-jose

Issue: gh-6025
This commit is contained in:
Josh Cummings 2018-11-20 14:02:10 -07:00
parent 9ee291e659
commit 2a8233d035
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
3 changed files with 12 additions and 24 deletions

View File

@ -21,6 +21,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
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.ReactiveOAuth2AccessTokenResponseClient;
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.TestOAuth2AuthorizationRequests;
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.assertThatCode;
import static org.mockito.ArgumentMatchers.any;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
/**
* @author Rob Winch

View File

@ -16,36 +16,32 @@
package org.springframework.security.oauth2.core.endpoint;
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.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}.
*
* @author Joe Grandja
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({OAuth2AuthorizationExchange.class, OAuth2AuthorizationRequest.class, OAuth2AuthorizationResponse.class})
public class OAuth2AuthorizationExchangeTests {
@Test(expected = IllegalArgumentException.class)
public void constructorWhenAuthorizationRequestIsNullThenThrowIllegalArgumentException() {
new OAuth2AuthorizationExchange(null, mock(OAuth2AuthorizationResponse.class));
new OAuth2AuthorizationExchange(null, success().build());
}
@Test(expected = IllegalArgumentException.class)
public void constructorWhenAuthorizationResponseIsNullThenThrowIllegalArgumentException() {
new OAuth2AuthorizationExchange(mock(OAuth2AuthorizationRequest.class), null);
new OAuth2AuthorizationExchange(request().build(), null);
}
@Test
public void constructorWhenRequiredArgsProvidedThenCreated() {
OAuth2AuthorizationRequest authorizationRequest = mock(OAuth2AuthorizationRequest.class);
OAuth2AuthorizationResponse authorizationResponse = mock(OAuth2AuthorizationResponse.class);
OAuth2AuthorizationRequest authorizationRequest = request().build();
OAuth2AuthorizationResponse authorizationResponse = success().build();
OAuth2AuthorizationExchange authorizationExchange =
new OAuth2AuthorizationExchange(authorizationRequest, authorizationResponse);
assertThat(authorizationExchange.getAuthorizationRequest()).isEqualTo(authorizationRequest);

View File

@ -20,16 +20,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.nimbusds.jwt.JWTParser;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.assertj.core.api.Assertions;
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.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.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
/**
* Tests for {@link NimbusJwtDecoderJwkSupport}.
@ -58,9 +52,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
* @author Joe Grandja
* @author Josh Cummings
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({NimbusJwtDecoderJwkSupport.class, JWTParser.class})
@PowerMockIgnore("okhttp3.*")
public class NimbusJwtDecoderJwkSupportTests {
private static final String JWK_SET_URL = "https://provider.com/oauth2/keys";
private static final String JWS_ALGORITHM = JwsAlgorithms.RS256;
@ -248,7 +239,7 @@ public class NimbusJwtDecoderJwkSupportTests {
private static RestOperations mockJwkSetResponse(String response) {
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));
return restOperations;
}