Skip to content

Commit

Permalink
Fix error in mock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steniobhz committed Oct 16, 2024
1 parent 55ab41b commit 8feb386
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ public void testHandleListenerSearch_MissingQueryParam() {
when(request.method()).thenReturn(HttpMethod.GET);
when(request.getParam("q")).thenReturn("");
when(request.response()).thenReturn(response);
when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());

RoutingContext routingContext = mock(RoutingContext.class);
when(routingContext.request()).thenReturn(request);
Expand Down Expand Up @@ -746,28 +747,28 @@ public void testHandleListenerWithStorageAndSearchFailure(TestContext context) {
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
HttpServerResponse response = Mockito.mock(HttpServerResponse.class);

// Simulate a GET request without a query parameter
// Mock necessary methods
Mockito.when(request.method()).thenReturn(HttpMethod.GET);
Mockito.when(request.uri()).thenReturn("hookRootURI/registrations/listeners/");
Mockito.when(request.getParam("q")).thenReturn(null); // No query parameter
Mockito.when(request.getParam("q")).thenReturn(null); // No query param
Mockito.when(request.response()).thenReturn(response);
Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());

Mockito.when(routingContext.request()).thenReturn(request);

// Async handler to check the result
Async async = context.async();
HttpClient selfClient = Mockito.mock(HttpClient.class);
Mockito.when(selfClient.request(Mockito.any(), Mockito.anyString())).thenReturn(Future.failedFuture(new Exception("Mocked failure")));

// Act: Call the hookHandler.handle method
Mockito.when(routingContext.request()).thenReturn(request);

// Act
boolean handled = hookHandler.handle(routingContext);

// Assert that it was NOT handled (as the query param is missing)
// Assert
context.assertFalse(handled);

// Verify that the response was NOT ended (because it shouldn't be processed)
Mockito.verify(response, Mockito.never()).end();
async.complete();
}


@Test
public void testSearchMultipleListeners_Success(TestContext context) {
Vertx vertx = Vertx.vertx();
Expand Down

0 comments on commit 8feb386

Please sign in to comment.