Skip to content

Commit

Permalink
Adding test for shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sashirestela committed Jan 16, 2025
1 parent 9854f23 commit 9064e44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ interface HttpProcessorTest {

void setMocksForStreamWithError(Stream<String> result) throws IOException, URISyntaxException;

void testShutdown();

@BeforeAll
static void setup() {
TestSupport.setupConfigurator();
Expand Down Expand Up @@ -343,4 +345,9 @@ default void shouldExecuteDefaultMethodWhenItIsCalled() {
assertEquals(expectedValue, actualValue);
}

@Test
default void shouldShutdownWithoutExceptions() {
testShutdown();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -146,4 +148,14 @@ public void setMocksForStreamWithError(Stream<String> result) throws IOException
when(httpResponseStream.request()).thenReturn(httpRequest);
}

@Override
public void testShutdown() {
var defaultAdapter = new JavaHttpClientAdapter();
assertDoesNotThrow(() -> defaultAdapter.shutdown());

var client = HttpClient.newBuilder().executor(Executors.newFixedThreadPool(2)).build();
var customAdapter = new JavaHttpClientAdapter(client);
assertDoesNotThrow(() -> customAdapter.shutdown());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -179,4 +180,14 @@ public void setMocksForStreamWithError(Stream<String> result) throws IOException
when(okHttpResponse.request()).thenReturn(okHttpRequest);
}

@Override
public void testShutdown() {
var defaultAdapter = new OkHttpClientAdapter();
assertDoesNotThrow(() -> defaultAdapter.shutdown());

var client = new OkHttpClient();
var customAdapter = new OkHttpClientAdapter(client);
assertDoesNotThrow(() -> customAdapter.shutdown());
}

}

0 comments on commit 9064e44

Please sign in to comment.