Migrate to BDD Mockito
Migrate Mockito imports to use the BDD variant. This aligns better with the "given" / "when" / "then" style used in most tests since the "given" block now uses Mockito `given(...)` calls. The commit also updates a few tests that were accidentally using Power Mockito when regular Mockito could be used. Issue gh-8945
This commit is contained in:
+4
-4
@@ -55,9 +55,9 @@ import org.springframework.util.MimeTypeUtils;
|
||||
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.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -84,7 +84,7 @@ public class AuthenticationPayloadInterceptorTests {
|
||||
AuthenticationPayloadInterceptor interceptor = new AuthenticationPayloadInterceptor(this.authenticationManager);
|
||||
PayloadExchange exchange = createExchange();
|
||||
TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.just(expectedAuthentication));
|
||||
given(this.authenticationManager.authenticate(any())).willReturn(Mono.just(expectedAuthentication));
|
||||
|
||||
AuthenticationPayloadInterceptorChain authenticationPayloadChain = new AuthenticationPayloadInterceptorChain();
|
||||
interceptor.intercept(exchange, authenticationPayloadChain).block();
|
||||
@@ -103,11 +103,11 @@ public class AuthenticationPayloadInterceptorTests {
|
||||
|
||||
PayloadExchange exchange = createExchange();
|
||||
TestingAuthenticationToken expectedAuthentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.authenticationManager.authenticate(any())).thenReturn(Mono.just(expectedAuthentication));
|
||||
given(this.authenticationManager.authenticate(any())).willReturn(Mono.just(expectedAuthentication));
|
||||
|
||||
PublisherProbe<Void> voidResult = PublisherProbe.empty();
|
||||
PayloadInterceptorChain chain = mock(PayloadInterceptorChain.class);
|
||||
when(chain.next(any())).thenReturn(voidResult.mono());
|
||||
given(chain.next(any())).willReturn(voidResult.mono());
|
||||
|
||||
StepVerifier.create(interceptor.intercept(exchange, chain))
|
||||
.then(() -> assertThat(voidResult.subscribeCount()).isEqualTo(1)).verifyComplete();
|
||||
|
||||
+6
-6
@@ -34,7 +34,7 @@ import org.springframework.security.rsocket.api.PayloadExchange;
|
||||
import org.springframework.security.rsocket.api.PayloadInterceptorChain;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.security.authorization.AuthenticatedReactiveAuthorizationManager.authenticated;
|
||||
import static org.springframework.security.authorization.AuthorityReactiveAuthorizationManager.hasRole;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void interceptWhenAuthenticationEmptyAndSubscribedThenException() {
|
||||
when(this.chain.next(any())).thenReturn(this.chainResult.mono());
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(authenticated());
|
||||
|
||||
@@ -70,8 +70,8 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void interceptWhenAuthenticationNotSubscribedAndEmptyThenCompletes() {
|
||||
when(this.chain.next(any())).thenReturn(this.chainResult.mono());
|
||||
when(this.authorizationManager.verify(any(), any())).thenReturn(this.managerResult.mono());
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
given(this.authorizationManager.verify(any(), any())).willReturn(this.managerResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(this.authorizationManager);
|
||||
|
||||
@@ -81,7 +81,7 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void interceptWhenNotAuthorizedThenException() {
|
||||
when(this.chain.next(any())).thenReturn(this.chainResult.mono());
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(hasRole("USER"));
|
||||
Context userContext = ReactiveSecurityContextHolder
|
||||
@@ -95,7 +95,7 @@ public class AuthorizationPayloadInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void interceptWhenAuthorizedThenContinues() {
|
||||
when(this.chain.next(any())).thenReturn(this.chainResult.mono());
|
||||
given(this.chain.next(any())).willReturn(this.chainResult.mono());
|
||||
|
||||
AuthorizationPayloadInterceptor interceptor = new AuthorizationPayloadInterceptor(authenticated());
|
||||
Context userContext = ReactiveSecurityContextHolder
|
||||
|
||||
+5
-5
@@ -32,7 +32,7 @@ import org.springframework.security.rsocket.util.matcher.PayloadExchangeMatchers
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -52,7 +52,7 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenGrantedThenGranted() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(true);
|
||||
when(this.authz.check(any(), any())).thenReturn(Mono.just(expected));
|
||||
given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
|
||||
PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz))
|
||||
.build();
|
||||
@@ -63,7 +63,7 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenDeniedThenDenied() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(false);
|
||||
when(this.authz.check(any(), any())).thenReturn(Mono.just(expected));
|
||||
given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
|
||||
PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz))
|
||||
.build();
|
||||
@@ -74,7 +74,7 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenFirstMatchThenSecondUsed() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(true);
|
||||
when(this.authz.check(any(), any())).thenReturn(Mono.just(expected));
|
||||
given(this.authz.check(any(), any())).willReturn(Mono.just(expected));
|
||||
PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
.builder().add(new PayloadExchangeMatcherEntry<>(PayloadExchangeMatchers.anyExchange(), this.authz))
|
||||
.add(new PayloadExchangeMatcherEntry<>(e -> PayloadExchangeMatcher.MatchResult.notMatch(), this.authz2))
|
||||
@@ -86,7 +86,7 @@ public class PayloadExchangeMatcherReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenSecondMatchThenSecondUsed() {
|
||||
AuthorizationDecision expected = new AuthorizationDecision(true);
|
||||
when(this.authz2.check(any(), any())).thenReturn(Mono.just(expected));
|
||||
given(this.authz2.check(any(), any())).willReturn(Mono.just(expected));
|
||||
PayloadExchangeMatcherReactiveAuthorizationManager manager = PayloadExchangeMatcherReactiveAuthorizationManager
|
||||
.builder()
|
||||
.add(new PayloadExchangeMatcherEntry<>(e -> PayloadExchangeMatcher.MatchResult.notMatch(), this.authz))
|
||||
|
||||
+35
-35
@@ -54,9 +54,9 @@ 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.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -117,8 +117,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withChainNext());
|
||||
when(this.delegate.fireAndForget(any())).thenReturn(this.voidResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.delegate.fireAndForget(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -133,7 +133,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -149,8 +149,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void fireAndForgetWhenSecurityContextThenDelegateContext() {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withAuthenticated(authentication));
|
||||
when(this.delegate.fireAndForget(any())).thenReturn(Mono.empty());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.fireAndForget(any())).willReturn(Mono.empty());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
@@ -170,8 +170,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void requestResponseWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.empty());
|
||||
when(this.delegate.requestResponse(any())).thenReturn(this.payloadResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.requestResponse(any())).willReturn(this.payloadResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -188,7 +188,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void requestResponseWhenInterceptorErrorsThenDelegateNotInvoked() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -203,8 +203,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void requestResponseWhenSecurityContextThenDelegateContext() {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withAuthenticated(authentication));
|
||||
when(this.delegate.requestResponse(any())).thenReturn(this.payloadResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.requestResponse(any())).willReturn(this.payloadResult.mono());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
@@ -226,8 +226,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void requestStreamWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.empty());
|
||||
when(this.delegate.requestStream(any())).thenReturn(this.payloadResult.flux());
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.requestStream(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -242,7 +242,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void requestStreamWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -258,8 +258,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void requestStreamWhenSecurityContextThenDelegateContext() {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withAuthenticated(authentication));
|
||||
when(this.delegate.requestStream(any())).thenReturn(this.payloadResult.flux());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.requestStream(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
@@ -280,8 +280,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void requestChannelWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.empty());
|
||||
when(this.delegate.requestChannel(any())).thenReturn(this.payloadResult.flux());
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.requestChannel(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -298,7 +298,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void requestChannelWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -315,8 +315,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
public void requestChannelWhenSecurityContextThenDelegateContext() {
|
||||
Mono<Payload> payload = Mono.just(this.payload);
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withAuthenticated(authentication));
|
||||
when(this.delegate.requestChannel(any())).thenReturn(this.payloadResult.flux());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.requestChannel(any())).willReturn(this.payloadResult.flux());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
@@ -337,8 +337,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void metadataPushWhenInterceptorCompletesThenDelegateSubscribed() {
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.empty());
|
||||
when(this.delegate.metadataPush(any())).thenReturn(this.voidResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
given(this.delegate.metadataPush(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -353,7 +353,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void metadataPushWhenInterceptorErrorsThenDelegateNotSubscribed() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -368,8 +368,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void metadataPushWhenSecurityContextThenDelegateContext() {
|
||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken("user", "password");
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withAuthenticated(authentication));
|
||||
when(this.delegate.metadataPush(any())).thenReturn(this.voidResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withAuthenticated(authentication));
|
||||
given(this.delegate.metadataPush(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
RSocket assertAuthentication = new RSocketProxy(this.delegate) {
|
||||
@Override
|
||||
@@ -392,9 +392,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptorsCompleteThenDelegateInvoked() {
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withChainNext());
|
||||
when(this.interceptor2.intercept(any(), any())).thenAnswer(withChainNext());
|
||||
when(this.delegate.fireAndForget(any())).thenReturn(this.voidResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.interceptor2.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.delegate.fireAndForget(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -408,9 +408,9 @@ public class PayloadInterceptorRSocketTests {
|
||||
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptorsMutatesPayloadThenDelegateInvoked() {
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withChainNext());
|
||||
when(this.interceptor2.intercept(any(), any())).thenAnswer(withChainNext());
|
||||
when(this.delegate.fireAndForget(any())).thenReturn(this.voidResult.mono());
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.interceptor2.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.delegate.fireAndForget(any())).willReturn(this.voidResult.mono());
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -427,7 +427,7 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptor1ErrorsThenInterceptor2AndDelegateNotInvoked() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
@@ -443,8 +443,8 @@ public class PayloadInterceptorRSocketTests {
|
||||
@Test
|
||||
public void fireAndForgetWhenInterceptor2ErrorsThenInterceptor2AndDelegateNotInvoked() {
|
||||
RuntimeException expected = new RuntimeException("Oops");
|
||||
when(this.interceptor.intercept(any(), any())).thenAnswer(withChainNext());
|
||||
when(this.interceptor2.intercept(any(), any())).thenReturn(Mono.error(expected));
|
||||
given(this.interceptor.intercept(any(), any())).willAnswer(withChainNext());
|
||||
given(this.interceptor2.intercept(any(), any())).willReturn(Mono.error(expected));
|
||||
|
||||
PayloadInterceptorRSocket interceptor = new PayloadInterceptorRSocket(this.delegate,
|
||||
Arrays.asList(this.interceptor, this.interceptor2), this.metadataMimeType, this.dataMimeType);
|
||||
|
||||
+6
-6
@@ -38,9 +38,9 @@ import org.springframework.security.rsocket.api.PayloadInterceptor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -75,7 +75,7 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void applyWhenDefaultMetadataMimeTypeThenDefaulted() {
|
||||
when(this.setupPayload.dataMimeType()).thenReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
@@ -87,7 +87,7 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
@Test
|
||||
public void acceptWhenDefaultMetadataMimeTypeOverrideThenDefaulted() {
|
||||
this.acceptorInterceptor.setDefaultMetadataMimeType(MediaType.APPLICATION_JSON);
|
||||
when(this.setupPayload.dataMimeType()).thenReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
@@ -107,15 +107,15 @@ public class PayloadSocketAcceptorInterceptorTests {
|
||||
}
|
||||
|
||||
private PayloadExchange captureExchange() {
|
||||
when(this.socketAcceptor.accept(any(), any())).thenReturn(Mono.just(this.rSocket));
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.empty());
|
||||
given(this.socketAcceptor.accept(any(), any())).willReturn(Mono.just(this.rSocket));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
|
||||
SocketAcceptor wrappedAcceptor = this.acceptorInterceptor.apply(this.socketAcceptor);
|
||||
RSocket result = wrappedAcceptor.accept(this.setupPayload, this.rSocket).block();
|
||||
|
||||
assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
|
||||
|
||||
when(this.rSocket.fireAndForget(any())).thenReturn(Mono.empty());
|
||||
given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
|
||||
|
||||
result.fireAndForget(this.payload).block();
|
||||
|
||||
|
||||
+10
-10
@@ -45,9 +45,9 @@ import org.springframework.security.rsocket.api.PayloadInterceptor;
|
||||
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.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -106,7 +106,7 @@ public class PayloadSocketAcceptorTests {
|
||||
|
||||
@Test
|
||||
public void acceptWhenDefaultMetadataMimeTypeThenDefaulted() {
|
||||
when(this.setupPayload.dataMimeType()).thenReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
@@ -118,7 +118,7 @@ public class PayloadSocketAcceptorTests {
|
||||
@Test
|
||||
public void acceptWhenDefaultMetadataMimeTypeOverrideThenDefaulted() {
|
||||
this.acceptor.setDefaultMetadataMimeType(MediaType.APPLICATION_JSON);
|
||||
when(this.setupPayload.dataMimeType()).thenReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
@@ -139,8 +139,8 @@ public class PayloadSocketAcceptorTests {
|
||||
|
||||
@Test
|
||||
public void acceptWhenExplicitMimeTypeThenThenOverrideDefault() {
|
||||
when(this.setupPayload.metadataMimeType()).thenReturn(MediaType.TEXT_PLAIN_VALUE);
|
||||
when(this.setupPayload.dataMimeType()).thenReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
given(this.setupPayload.metadataMimeType()).willReturn(MediaType.TEXT_PLAIN_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
PayloadExchange exchange = captureExchange();
|
||||
|
||||
@@ -151,8 +151,8 @@ public class PayloadSocketAcceptorTests {
|
||||
@Test
|
||||
// gh-8654
|
||||
public void acceptWhenDelegateAcceptRequiresReactiveSecurityContext() {
|
||||
when(this.setupPayload.metadataMimeType()).thenReturn(MediaType.TEXT_PLAIN_VALUE);
|
||||
when(this.setupPayload.dataMimeType()).thenReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
given(this.setupPayload.metadataMimeType()).willReturn(MediaType.TEXT_PLAIN_VALUE);
|
||||
given(this.setupPayload.dataMimeType()).willReturn(MediaType.APPLICATION_JSON_VALUE);
|
||||
SecurityContext expectedSecurityContext = new SecurityContextImpl(
|
||||
new TestingAuthenticationToken("user", "password", "ROLE_USER"));
|
||||
CaptureSecurityContextSocketAcceptor captureSecurityContext = new CaptureSecurityContextSocketAcceptor(
|
||||
@@ -171,14 +171,14 @@ public class PayloadSocketAcceptorTests {
|
||||
}
|
||||
|
||||
private PayloadExchange captureExchange() {
|
||||
when(this.delegate.accept(any(), any())).thenReturn(Mono.just(this.rSocket));
|
||||
when(this.interceptor.intercept(any(), any())).thenReturn(Mono.empty());
|
||||
given(this.delegate.accept(any(), any())).willReturn(Mono.just(this.rSocket));
|
||||
given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
|
||||
|
||||
RSocket result = this.acceptor.accept(this.setupPayload, this.rSocket).block();
|
||||
|
||||
assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
|
||||
|
||||
when(this.rSocket.fireAndForget(any())).thenReturn(Mono.empty());
|
||||
given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
|
||||
|
||||
result.fireAndForget(this.payload).block();
|
||||
|
||||
|
||||
+12
-12
@@ -38,7 +38,7 @@ import org.springframework.util.RouteMatcher;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -77,7 +77,7 @@ public class RoutePayloadExchangeMatcherTests {
|
||||
|
||||
@Test
|
||||
public void matchesWhenNoRouteThenNotMatch() {
|
||||
when(this.metadataExtractor.extract(any(), any())).thenReturn(Collections.emptyMap());
|
||||
given(this.metadataExtractor.extract(any(), any())).willReturn(Collections.emptyMap());
|
||||
PayloadExchangeMatcher.MatchResult result = this.matcher.matches(this.exchange).block();
|
||||
assertThat(result.isMatch()).isFalse();
|
||||
}
|
||||
@@ -85,8 +85,8 @@ public class RoutePayloadExchangeMatcherTests {
|
||||
@Test
|
||||
public void matchesWhenNotMatchThenNotMatch() {
|
||||
String route = "route";
|
||||
when(this.metadataExtractor.extract(any(), any()))
|
||||
.thenReturn(Collections.singletonMap(MetadataExtractor.ROUTE_KEY, route));
|
||||
given(this.metadataExtractor.extract(any(), any()))
|
||||
.willReturn(Collections.singletonMap(MetadataExtractor.ROUTE_KEY, route));
|
||||
PayloadExchangeMatcher.MatchResult result = this.matcher.matches(this.exchange).block();
|
||||
assertThat(result.isMatch()).isFalse();
|
||||
}
|
||||
@@ -94,10 +94,10 @@ public class RoutePayloadExchangeMatcherTests {
|
||||
@Test
|
||||
public void matchesWhenMatchAndNoVariablesThenMatch() {
|
||||
String route = "route";
|
||||
when(this.metadataExtractor.extract(any(), any()))
|
||||
.thenReturn(Collections.singletonMap(MetadataExtractor.ROUTE_KEY, route));
|
||||
when(this.routeMatcher.parseRoute(any())).thenReturn(this.route);
|
||||
when(this.routeMatcher.matchAndExtract(any(), any())).thenReturn(Collections.emptyMap());
|
||||
given(this.metadataExtractor.extract(any(), any()))
|
||||
.willReturn(Collections.singletonMap(MetadataExtractor.ROUTE_KEY, route));
|
||||
given(this.routeMatcher.parseRoute(any())).willReturn(this.route);
|
||||
given(this.routeMatcher.matchAndExtract(any(), any())).willReturn(Collections.emptyMap());
|
||||
PayloadExchangeMatcher.MatchResult result = this.matcher.matches(this.exchange).block();
|
||||
assertThat(result.isMatch()).isTrue();
|
||||
}
|
||||
@@ -106,10 +106,10 @@ public class RoutePayloadExchangeMatcherTests {
|
||||
public void matchesWhenMatchAndVariablesThenMatchAndVariables() {
|
||||
String route = "route";
|
||||
Map<String, String> variables = Collections.singletonMap("a", "b");
|
||||
when(this.metadataExtractor.extract(any(), any()))
|
||||
.thenReturn(Collections.singletonMap(MetadataExtractor.ROUTE_KEY, route));
|
||||
when(this.routeMatcher.parseRoute(any())).thenReturn(this.route);
|
||||
when(this.routeMatcher.matchAndExtract(any(), any())).thenReturn(variables);
|
||||
given(this.metadataExtractor.extract(any(), any()))
|
||||
.willReturn(Collections.singletonMap(MetadataExtractor.ROUTE_KEY, route));
|
||||
given(this.routeMatcher.parseRoute(any())).willReturn(this.route);
|
||||
given(this.routeMatcher.matchAndExtract(any(), any())).willReturn(variables);
|
||||
PayloadExchangeMatcher.MatchResult result = this.matcher.matches(this.exchange).block();
|
||||
assertThat(result.isMatch()).isTrue();
|
||||
assertThat(result.getVariables()).containsAllEntriesOf(variables);
|
||||
|
||||
Reference in New Issue
Block a user