Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Mockito 3 #509

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion components/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -385,7 +386,7 @@ public void sendsToDefaultHttpPort() {
.stream(),
new StyxHttpClient.Builder());

verify(factory).createConnection(originCaptor.capture(), any(ConnectionSettings.class), any(SslContext.class));
verify(factory).createConnection(originCaptor.capture(), any(ConnectionSettings.class), nullable(SslContext.class));
assertThat(originCaptor.getValue().port(), is(80));
}

Expand All @@ -410,7 +411,7 @@ public void sendsToDefaultHttpsPort() {

private static NettyConnectionFactory mockConnectionFactory() {
NettyConnectionFactory factory = mock(NettyConnectionFactory.class);
when(factory.createConnection(any(Origin.class), any(ConnectionSettings.class), any(SslContext.class)))
when(factory.createConnection(any(Origin.class), any(ConnectionSettings.class), nullable(SslContext.class)))
.thenReturn(Mono.just(mock(Connection.class)));
return factory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2018 Expedia Inc.
Copyright (C) 2013-2019 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@
import static java.util.Optional.of;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void shouldNotRetryBasedOnExceptionOtherThanIsRetryableException() {
@Test
public void returnsPreviouslyNonAttemptedOrigin() {
when(retryPolicyContext.previousOrigins()).thenReturn(Collections.emptyList());
when(loadBalancer.choose(any(LoadBalancer.Preferences.class))).thenReturn(of(remoteHost));
when(loadBalancer.choose(nullable(LoadBalancer.Preferences.class))).thenReturn(of(remoteHost));

RetryPolicy.Outcome retryOutcome = new RetryNTimes(1).evaluate(
retryPolicyContext, loadBalancer, null);
Expand Down
2 changes: 1 addition & 1 deletion components/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion components/proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion components/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.hotels.styx.server.netty.connectors;

import com.google.common.collect.ObjectArrays;
import com.hotels.styx.api.ContentOverflowException;
import com.hotels.styx.api.Eventual;
import com.hotels.styx.api.HttpHandler;
Expand Down Expand Up @@ -89,6 +88,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.core.Is.is;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
Expand Down Expand Up @@ -151,20 +151,21 @@ public void setUp() throws Exception {
writerFuture = new CompletableFuture<>();

responseWriter = mock(HttpResponseWriter.class);
when(responseWriter.write(any(LiveHttpResponse.class))).thenReturn(writerFuture);
when(responseWriter.write(nullable(LiveHttpResponse.class))).thenReturn(writerFuture);

responseWriterFactory = mock(HttpResponseWriterFactory.class);
when(responseWriterFactory.create(anyObject()))
when(responseWriterFactory.create(nullable(ChannelHandlerContext.class)))
.thenReturn(responseWriter);

pipeline = mock(HttpHandler.class);
when(pipeline.handle(anyObject(), any(HttpInterceptor.Context.class))).thenReturn(new Eventual<>(toPublisher(responseObservable.doOnUnsubscribe(() -> responseUnsubscribed.set(true)))));
when(pipeline.handle(nullable(LiveHttpRequest.class), nullable(HttpInterceptor.Context.class))).thenReturn(new Eventual<>(toPublisher(responseObservable.doOnUnsubscribe(() -> responseUnsubscribed.set(true)))));

request = get("/foo").id("REQUEST-1-ID").build();
response = response().build();

responseEnhancer = mock(ResponseEnhancer.class);
when(responseEnhancer.enhance(any(LiveHttpResponse.Transformer.class), any(LiveHttpRequest.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
when(responseEnhancer.enhance(nullable(LiveHttpResponse.Transformer.class), nullable(LiveHttpRequest.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
when(responseEnhancer.enhance(nullable(LiveHttpResponse.class), nullable(LiveHttpRequest.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);

setupHandlerTo(ACCEPTING_REQUESTS);
}
Expand Down Expand Up @@ -234,8 +235,8 @@ public void mapsWrappedBadRequestExceptionToBadRequest400ResponseCode() {
DefaultHttpResponse response = (DefaultHttpResponse) channel.readOutbound();

assertThat(response.getStatus(), is(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST));
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(null));
verify(errorListener, only()).proxyErrorOccurred(eq(BAD_REQUEST), any(BadRequestException.class));
verify(responseEnhancer).enhance(nullable(LiveHttpResponse.Transformer.class), eq(null));
verify(errorListener, only()).proxyErrorOccurred(eq(BAD_REQUEST), nullable(DecoderException.class));
}

@Test
Expand Down Expand Up @@ -494,7 +495,7 @@ public void closesConnectionWhenMultiplePrematureRequestsAreDetectedInSendingRes
responseObservable.onNext(response);
responseObservable.onCompleted();
assertThat(handler.state(), is(SENDING_RESPONSE));
verify(responseWriter).write(any(LiveHttpResponse.class));
verify(responseWriter).write(nullable(LiveHttpResponse.class));

// Receive second request, while still responding to the previous request.
// This request will be queued.
Expand Down Expand Up @@ -857,9 +858,9 @@ public void ioExceptionInSendingResponseState() throws Exception {
}

@Test
public void anotherxceptionInSendingResponseState() throws Exception {
public void anotherExceptionInSendingResponseState() throws Exception {
// In Sending Response state,
// An non-IO exception bubbles up the Netty pipeline
// A non-IO exception bubbles up the Netty pipeline
setupHandlerTo(SENDING_RESPONSE);

handler.exceptionCaught(ctx, new RuntimeException("something went wrong"));
Expand Down Expand Up @@ -1011,8 +1012,8 @@ private static ChannelHandlerContext mockCtx() {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
ChannelFuture future = channelFutureOk();
Channel channel = channel();
when(channel.writeAndFlush(any(ObjectArrays.class))).thenReturn(future);
when(ctx.writeAndFlush(any(Object.class))).thenReturn(future);
when(channel.writeAndFlush(nullable(Object.class))).thenReturn(future);
when(ctx.writeAndFlush(nullable(Object.class))).thenReturn(future);
when(ctx.channel()).thenReturn(channel);

when(ctx.channel().localAddress()).thenReturn(InetSocketAddress.createUnresolved("localhost", 1));
Expand Down
9 changes: 2 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

<!-- Testing Versions -->
<hamcrest.all.version>1.3</hamcrest.all.version>
<mockito.version>1.9.5</mockito.version>
<mockito.version>3.1.0</mockito.version>
<testng.version>6.14.3</testng.version>


Expand Down Expand Up @@ -486,7 +486,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
<exclusions>
Expand Down Expand Up @@ -968,11 +968,6 @@
<exclude>junit:junit:(,4.10]</exclude>
<exclude>junit:junit-dep</exclude>

<!--
Ban uber mockito.
-->
<!--<exclude>org.mockito:mockito-all</exclude>-->

<!--
Ban hamcrest so we can require compatible version (see includes).
-->
Expand Down
2 changes: 1 addition & 1 deletion support/test-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion support/testsupport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion system-tests/e2e-testsupport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>

</dependencies>
Expand Down