From 9064e44a2b2543618db7883284441e8598bc3f2a Mon Sep 17 00:00:00 2001 From: Sashir Estela Date: Thu, 16 Jan 2025 20:11:48 +0000 Subject: [PATCH] Adding test for shutdown --- .../cleverclient/http/HttpProcessorTest.java | 7 +++++++ .../cleverclient/http/JavaHttpProcessorTest.java | 12 ++++++++++++ .../cleverclient/http/OkHttpProcessorTest.java | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java b/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java index 2b61f69..2f839ec 100644 --- a/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java +++ b/src/test/java/io/github/sashirestela/cleverclient/http/HttpProcessorTest.java @@ -39,6 +39,8 @@ interface HttpProcessorTest { void setMocksForStreamWithError(Stream result) throws IOException, URISyntaxException; + void testShutdown(); + @BeforeAll static void setup() { TestSupport.setupConfigurator(); @@ -343,4 +345,9 @@ default void shouldExecuteDefaultMethodWhenItIsCalled() { assertEquals(expectedValue, actualValue); } + @Test + default void shouldShutdownWithoutExceptions() { + testShutdown(); + } + } diff --git a/src/test/java/io/github/sashirestela/cleverclient/http/JavaHttpProcessorTest.java b/src/test/java/io/github/sashirestela/cleverclient/http/JavaHttpProcessorTest.java index 40078b5..93cf9de 100644 --- a/src/test/java/io/github/sashirestela/cleverclient/http/JavaHttpProcessorTest.java +++ b/src/test/java/io/github/sashirestela/cleverclient/http/JavaHttpProcessorTest.java @@ -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; @@ -146,4 +148,14 @@ public void setMocksForStreamWithError(Stream 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()); + } + } diff --git a/src/test/java/io/github/sashirestela/cleverclient/http/OkHttpProcessorTest.java b/src/test/java/io/github/sashirestela/cleverclient/http/OkHttpProcessorTest.java index 0f4bd03..43ba99f 100644 --- a/src/test/java/io/github/sashirestela/cleverclient/http/OkHttpProcessorTest.java +++ b/src/test/java/io/github/sashirestela/cleverclient/http/OkHttpProcessorTest.java @@ -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; @@ -179,4 +180,14 @@ public void setMocksForStreamWithError(Stream 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()); + } + }