Skip to content

Commit

Permalink
Updated mockito dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mcweba committed Jan 16, 2024
1 parent ab8b749 commit c7fef85
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testNotSupportedCacheControlHeadersAreNotHandled(TestContext context
Request cacheControlMaxAgeZero = new Request(HttpMethod.GET, "/some/path", headers, response);
context.assertFalse(cacheHandler.handle(cacheControlMaxAgeZero));

Mockito.verifyZeroInteractions(response);
Mockito.verifyNoInteractions(response);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import static org.awaitility.Awaitility.await;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.swisspush.gateleen.cache.storage.RedisCacheStorage.CACHED_REQUESTS;
import static org.swisspush.gateleen.cache.storage.RedisCacheStorage.CACHE_PREFIX;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.swisspush.gateleen.core.http.DummyHttpServerResponse;
import org.swisspush.gateleen.core.storage.MockResourceStorage;
Expand All @@ -18,8 +18,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.swisspush.gateleen.core.configuration.ConfigurationResourceManager.CONFIG_RESOURCE_CHANGED_ADDRESS;

Expand Down Expand Up @@ -202,7 +201,7 @@ public void testRegistrationAndInvalidUpdateWithSchema(TestContext context) {
// resource should still not be in storage after invalid update
context.assertFalse(storage.getMockData().containsKey(resourceURI));

verify(observer, Mockito.never()).resourceChanged(Matchers.anyString(), Matchers.any(Buffer.class));
verify(observer, Mockito.never()).resourceChanged(anyString(), any(Buffer.class));
async.complete();
}

Expand Down Expand Up @@ -241,7 +240,7 @@ public void testNoNotificationAfterUnsuccessfulStoragePut(TestContext context) t

context.assertEquals(storagePutFailStatusCode, response.getStatusCode());

verify(observer, Mockito.never()).resourceChanged(anyString(), Matchers.any(Buffer.class));
verify(observer, Mockito.never()).resourceChanged(anyString(), any(Buffer.class));
async.complete();
}

Expand All @@ -266,9 +265,9 @@ public void testNotSupportedConfigurationResourceChangeType(TestContext context)
vertx.eventBus().publish(CONFIG_RESOURCE_CHANGED_ADDRESS, object);

// only 1 occurence of Storage.get is allowed during registerObserver. The second call would have come after the publish
verify(storage, times(1)).get(Matchers.anyString(), Matchers.any());
verify(storage, times(1)).get(anyString(), any());

verify(observer, Mockito.never()).resourceChanged(Matchers.anyString(), Matchers.any(Buffer.class));
verify(observer, Mockito.never()).resourceChanged(anyString(), any(Buffer.class));
async.complete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.swisspush.gateleen.core.util.Address;
import org.swisspush.gateleen.core.util.StatusCode;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.swisspush.gateleen.core.logging.RequestLogger.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.slf4j.Logger;
import org.swisspush.gateleen.core.lock.Lock;

import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;

/**
* Tests for the {@link LockUtil} class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import java.util.HashMap;

import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.swisspush.gateleen.core.util.ResourcesUtils.loadResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.swisspush.gateleen.core.http.DummyHttpServerRequest;
import org.swisspush.gateleen.core.http.DummyHttpServerResponse;
import org.swisspush.gateleen.core.redis.RedisProvider;
Expand All @@ -27,7 +27,8 @@
import java.util.Arrays;
import java.util.List;

import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

@RunWith(VertxUnitRunner.class)
Expand All @@ -52,7 +53,7 @@ public void before() {
Handler<AsyncResult<Long>> handler = (Handler<AsyncResult<Long>>) invocation.getArguments()[1];
handler.handle(Future.succeededFuture(555L));
return null;
}).when(redisAPI).incr(eq("delta:sequence"), Matchers.any());
}).when(redisAPI).incr(eq("delta:sequence"), any());

requestHeaders = MultiMap.caseInsensitiveMultiMap();
requestHeaders.add("x-delta", "auto");
Expand Down Expand Up @@ -155,8 +156,8 @@ public void testDeltaNoExpiry() {
DeltaHandler deltaHandler = new DeltaHandler(redisProvider, null, ruleProvider);
deltaHandler.handle(request, router);

verify(redisAPI, times(1)).set(eq(Arrays.asList("delta:resources:a:b:c", "555")), Matchers.any());
verify(redisAPI, never()).setex(Matchers.any(), Matchers.any(), Matchers.any(), Matchers.any());
verify(redisAPI, times(1)).set(eq(Arrays.asList("delta:resources:a:b:c", "555")), any());
verify(redisAPI, never()).setex(any(), any(), any(), any());
}

@Test
Expand All @@ -166,8 +167,8 @@ public void testDeltaWithExpiry() {
DeltaHandler deltaHandler = new DeltaHandler(redisProvider, null, ruleProvider);
deltaHandler.handle(request, router);

verify(redisAPI, times(1)).setex(eq("delta:resources:a:b:c"), eq("123"), eq("555"), Matchers.any());
verify(redisAPI, never()).set(Matchers.any(), Matchers.any());
verify(redisAPI, times(1)).setex(eq("delta:resources:a:b:c"), eq("123"), eq("555"), any());
verify(redisAPI, never()).set(any(), any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void testBadRequestResponseForInvalidExpandParameterRequests(TestContext
verify(response, times(1)).setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage());
verify(response, times(1)).end("Expand parameter is not valid. Must be a positive number");

verifyZeroInteractions(httpClient);
verifyNoInteractions(httpClient);
}

@Test
Expand All @@ -271,7 +271,7 @@ public void testBadRequestResponseForExceedingMaxExpansionLevelHard(TestContext
verify(response, times(1)).setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage());
verify(response, times(1)).end("Expand level '15' is greater than the maximum expand level '10'");

verifyZeroInteractions(httpClient);
verifyNoInteractions(httpClient);
}

private static class Request extends DummyHttpServerRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import static io.vertx.core.http.HttpMethod.PUT;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.swisspush.gateleen.core.util.HttpRequestHeader.*;

/**
Expand Down Expand Up @@ -133,15 +133,11 @@ public void testListenerEnqueueWithDefaultQueueingStrategy(TestContext context)
hookHandler.handle(routingContext);

// verify that enqueue has been called WITH the payload
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(Object argument) {
HttpRequest req = (HttpRequest) argument;
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(req -> {
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}), anyString(), any(Handler.class));
}

Expand All @@ -163,15 +159,11 @@ public void testListenerEnqueueWithDefaultQueueingStrategyBecauseOfInvalidConfig
hookHandler.handle(routingContext);

// verify that enqueue has been called WITH the payload
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(Object argument) {
HttpRequest req = (HttpRequest) argument;
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(req -> {
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}), anyString(), any(Handler.class));
}

Expand All @@ -192,31 +184,23 @@ public void testListenerEnqueueWithDiscardPayloadQueueingStrategy(TestContext co
hookHandler.handle(routingContext);

// verify that enqueue has been called WITHOUT the payload but with 'Content-Length : 0' header
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(Object argument) {
HttpRequest req = (HttpRequest) argument;
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(0).equals(getInteger(req.getHeaders(), CONTENT_LENGTH))
&& Arrays.equals(req.getPayload(), new byte[0]); // should not be original payload anymore
}
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(req -> {
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(0).equals(getInteger(req.getHeaders(), CONTENT_LENGTH))
&& Arrays.equals(req.getPayload(), new byte[0]); // should not be original payload anymore
}), anyString(), any(Handler.class));

PUTRequest putRequestWithoutContentLengthHeader = new PUTRequest(uri, originalPayload);
Mockito.when(routingContext.request()).thenReturn(putRequestWithoutContentLengthHeader);
hookHandler.handle(routingContext);

// verify that enqueue has been called WITHOUT the payload and WITHOUT 'Content-Length' header
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(Object argument) {
HttpRequest req = (HttpRequest) argument;
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& !containsHeader(req.getHeaders(), CONTENT_LENGTH)
&& Arrays.equals(req.getPayload(), new byte[0]); // should not be original payload anymore
}
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(req -> {
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& !containsHeader(req.getHeaders(), CONTENT_LENGTH)
&& Arrays.equals(req.getPayload(), new byte[0]); // should not be original payload anymore
}), anyString(), any(Handler.class));
}

Expand All @@ -241,8 +225,8 @@ public void testListenerEnqueueWithReducedPropagationQueueingStrategyButNoManage
hookHandler.handle(routingContext);

// verify that no enqueue (or lockedEnqueue) has been called because no ReducedPropagationManager was configured
Mockito.verifyZeroInteractions(requestQueue);
Mockito.verifyZeroInteractions(reducedPropagationManager);
Mockito.verifyNoInteractions(requestQueue);
Mockito.verifyNoInteractions(reducedPropagationManager);
}

@Test
Expand Down Expand Up @@ -289,15 +273,11 @@ public void testListenerEnqueueWithInvalidReducedPropagationQueueingStrategy(Tes
hookHandler.handle(routingContext);

// verify that enqueue has been called WITH the payload
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(Object argument) {
HttpRequest req = (HttpRequest) argument;
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(req -> {
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}), anyString(), any(Handler.class));
}

Expand All @@ -320,15 +300,11 @@ public void testListenerEnqueueWithMatchingRequestsHeaderFilter(TestContext cont
hookHandler.handle(routingContext);

// verify that enqueue has been called WITH the payload
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(new ArgumentMatcher<>() {
@Override
public boolean matches(Object argument) {
HttpRequest req = (HttpRequest) argument;
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}
Mockito.verify(requestQueue, Mockito.timeout(2000).times(1)).enqueue(Mockito.argThat(req -> {
return HttpMethod.PUT == req.getMethod()
&& req.getUri().contains(uri)
&& Integer.valueOf(99).equals(getInteger(req.getHeaders(), CONTENT_LENGTH)) // Content-Length header should not have changed
&& Arrays.equals(req.getPayload(), Buffer.buffer(originalPayload).getBytes()); // payload should not have changed
}), anyString(), any(Handler.class));
}

Expand All @@ -349,7 +325,7 @@ public void testListenerNoEnqueueWithoutMatchingRequestsHeaderFilter(TestContext
hookHandler.handle(routingContext);

// verify that no enqueue has been called since the header did not match
Mockito.verifyZeroInteractions(requestQueue);
Mockito.verifyNoInteractions(requestQueue);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void testExpiredQueueProcessingGetQueueRequestFailure(TestContext context

verify(reducedPropagationStorage, timeout(1000).times(1)).getQueueRequest(eq(expiredQueue));
verify(reducedPropagationStorage, after(1000).never()).removeQueueRequest(anyString());
verifyZeroInteractions(requestQueue);
verifyNoInteractions(requestQueue);

async.complete();
});
Expand All @@ -331,7 +331,7 @@ public void testExpiredQueueProcessingGetQueueRequestReturnsNull(TestContext con

verify(reducedPropagationStorage, timeout(1000).times(1)).getQueueRequest(eq(expiredQueue));
verify(reducedPropagationStorage, after(1000).never()).removeQueueRequest(anyString());
verifyZeroInteractions(requestQueue);
verifyNoInteractions(requestQueue);

async.complete();
});
Expand Down
Loading

0 comments on commit c7fef85

Please sign in to comment.