diff --git a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientBuilderTest.java b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientBuilderTest.java index fb2a716b70..0d0d554cdc 100644 --- a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientBuilderTest.java +++ b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientBuilderTest.java @@ -26,12 +26,8 @@ */ package org.apache.hc.client5.http.rest; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.nio.charset.StandardCharsets; @@ -501,32 +497,32 @@ private T proxy(final Class iface) { void testGetSingleWidget() { final WidgetApi api = proxy(WidgetApi.class); final String json = api.get(42); - assertTrue(json.contains("\"id\":42")); - assertTrue(json.contains("\"name\":\"W-42\"")); + assertThat(json.contains("\"id\":42")).isTrue(); + assertThat(json.contains("\"name\":\"W-42\"")).isTrue(); } @Test void testGetWidgetList() { final WidgetApi api = proxy(WidgetApi.class); final String json = api.list(); - assertTrue(json.contains("\"name\":\"A\"")); - assertTrue(json.contains("\"name\":\"B\"")); + assertThat(json.contains("\"name\":\"A\"")).isTrue(); + assertThat(json.contains("\"name\":\"B\"")).isTrue(); } @Test void testPostWidget() { final WidgetApi api = proxy(WidgetApi.class); final String json = api.create("{\"id\":0,\"name\":\"New\"}"); - assertTrue(json.contains("\"id\":99")); - assertTrue(json.contains("\"name\":\"Created\"")); + assertThat(json.contains("\"id\":99")).isTrue(); + assertThat(json.contains("\"name\":\"Created\"")).isTrue(); } @Test void testPutWidget() { final WidgetApi api = proxy(WidgetApi.class); final String json = api.update(7, "{\"id\":0,\"name\":\"Up\"}"); - assertTrue(json.contains("\"id\":7")); - assertTrue(json.contains("\"name\":\"Updated\"")); + assertThat(json.contains("\"id\":7")).isTrue(); + assertThat(json.contains("\"name\":\"Updated\"")).isTrue(); } @Test @@ -538,130 +534,122 @@ void testDeleteWidget() { @Test void testQueryParam() { final EchoApi api = proxy(EchoApi.class); - assertEquals("hello", api.echo("hello")); + assertThat(api.echo("hello")).isEqualTo("hello"); } @Test void testMultiValueQueryParam() { final EchoApi api = proxy(EchoApi.class); final String result = api.echoMulti("alpha", "beta"); - assertTrue(result.contains("tag=alpha")); - assertTrue(result.contains("tag=beta")); + assertThat(result.contains("tag=alpha")).isTrue(); + assertThat(result.contains("tag=beta")).isTrue(); } @Test void testHeaderParam() { final EchoApi api = proxy(EchoApi.class); - assertEquals("myTag", api.echoHeader("myTag")); + assertThat(api.echoHeader("myTag")).isEqualTo("myTag"); } @Test void testErrorThrowsException() { final StatusApi api = proxy(StatusApi.class); - final RestClientResponseException ex = assertThrows( - RestClientResponseException.class, - () -> api.getStatus(404)); - assertEquals(404, ex.getStatusCode()); + final RestClientResponseException ex = assertThatExceptionOfType(RestClientResponseException.class).isThrownBy(() -> api.getStatus(404)).actual(); + assertThat(ex.getStatusCode()).isEqualTo(404); } @Test void testPathParamEncoding() { final EchoPathApi api = proxy(EchoPathApi.class); - assertEquals("hello%20world", api.echoPath("hello world")); - assertEquals("~user", api.echoPath("~user")); + assertThat(api.echoPath("hello world")).isEqualTo("hello%20world"); + assertThat(api.echoPath("~user")).isEqualTo("~user"); } @Test void testDefaultValue() { final DefaultsApi api = proxy(DefaultsApi.class); - assertEquals("red", api.withDefault(null)); - assertEquals("blue", api.withDefault("blue")); + assertThat(api.withDefault(null)).isEqualTo("red"); + assertThat(api.withDefault("blue")).isEqualTo("blue"); } @Test void testByteArrayReturn() { final BytesApi api = proxy(BytesApi.class); final byte[] data = api.getBytes(); - assertEquals("binary-data", new String(data, - StandardCharsets.UTF_8)); + assertThat(new String(data, + StandardCharsets.UTF_8)).isEqualTo("binary-data"); } @Test void testProxyToString() { final EchoApi api = proxy(EchoApi.class); - assertTrue(api.toString().startsWith("RestProxy[")); + assertThat(api.toString().startsWith("RestProxy[")).isTrue(); } @Test void testInferredContentTypeForStringBody() { final InspectApi api = proxy(InspectApi.class); final String ct = api.postString("hello"); - assertTrue(ct.startsWith("text/plain"), ct); + assertThat(ct.startsWith("text/plain")).as(ct).isTrue(); } @Test void testInferredContentTypeForByteArrayBody() { final InspectApi api = proxy(InspectApi.class); final String ct = api.postBytes(new byte[]{1, 2, 3}); - assertTrue(ct.startsWith("application/octet-stream"), ct); + assertThat(ct.startsWith("application/octet-stream")).as(ct).isTrue(); } @Test void testNoAcceptHeaderWithoutProduces() { final NoProduceApi api = proxy(NoProduceApi.class); - assertEquals("none", api.get()); + assertThat(api.get()).isEqualTo("none"); } @Test void testJsonPojoGet() { final JsonWidgetApi api = proxy(JsonWidgetApi.class); final Widget w = api.get(42); - assertEquals(42, w.id); - assertEquals("W-42", w.name); + assertThat(w.id).isEqualTo(42); + assertThat(w.name).isEqualTo("W-42"); } @Test void testJsonPojoPostRoundTrip() { final JsonWidgetApi api = proxy(JsonWidgetApi.class); final Widget w = api.create(new Widget(0, "New")); - assertEquals(0, w.id); - assertEquals("New", w.name); + assertThat(w.id).isEqualTo(0); + assertThat(w.name).isEqualTo("New"); } @Test void testJsonPojoErrorResponse() { final JsonErrorApi api = proxy(JsonErrorApi.class); - final RestClientResponseException ex = assertThrows( - RestClientResponseException.class, - () -> api.getError(500)); - assertEquals(500, ex.getStatusCode()); - assertNotNull(ex.getResponseBody()); + final RestClientResponseException ex = assertThatExceptionOfType(RestClientResponseException.class).isThrownBy(() -> api.getError(500)).actual(); + assertThat(ex.getStatusCode()).isEqualTo(500); + assertThat(ex.getResponseBody()).isNotNull(); } @Disabled("Custom JSON content types for POJO bodies not supported by current core API") void testPojoBodyHonorsConsumesMediaType() { final InspectJsonApi api = proxy(InspectJsonApi.class); final String ct = api.postJson(new Widget(1, "test")); - assertTrue(ct.startsWith("application/vnd.api+json"), ct); + assertThat(ct.startsWith("application/vnd.api+json")).as(ct).isTrue(); } @Test void testNonUtf8ErrorResponsePreservesBytes() { final CharStatusApi api = proxy(CharStatusApi.class); - final RestClientResponseException ex = assertThrows( - RestClientResponseException.class, - () -> api.getStatus(500)); - assertEquals(500, ex.getStatusCode()); - assertArrayEquals( - "caf\u00e9".getBytes(StandardCharsets.ISO_8859_1), - ex.getResponseBody()); + final RestClientResponseException ex = assertThatExceptionOfType(RestClientResponseException.class).isThrownBy(() -> api.getStatus(500)).actual(); + assertThat(ex.getStatusCode()).isEqualTo(500); + assertThat(ex.getResponseBody()).containsExactly("caf\u00e9".getBytes(StandardCharsets.ISO_8859_1)); } // --- Validation tests --- @Test void testRejectsNonInterface() { - assertThrows(IllegalArgumentException.class, () -> + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .baseUri("http://localhost") .httpClient(httpClient) @@ -670,7 +658,7 @@ void testRejectsNonInterface() { @Test void testRequiresBaseUri() { - assertThrows(IllegalStateException.class, () -> + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .httpClient(httpClient) .build(EchoApi.class)); @@ -678,7 +666,7 @@ void testRequiresBaseUri() { @Test void testRequiresHttpClient() { - assertThrows(IllegalStateException.class, () -> + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .baseUri("http://localhost") .build(EchoApi.class)); @@ -686,7 +674,7 @@ void testRequiresHttpClient() { @Test void testRejectsMultipleBodyParams() { - assertThrows(RestResourceException.class, () -> + assertThatExceptionOfType(RestResourceException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .baseUri("http://localhost") .httpClient(httpClient) @@ -695,7 +683,7 @@ void testRejectsMultipleBodyParams() { @Test void testRejectsPathParamMismatch() { - assertThrows(RestResourceException.class, () -> + assertThatExceptionOfType(RestResourceException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .baseUri("http://localhost") .httpClient(httpClient) @@ -704,7 +692,7 @@ void testRejectsPathParamMismatch() { @Test void testRejectsMissingPathParam() { - assertThrows(RestResourceException.class, () -> + assertThatExceptionOfType(RestResourceException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .baseUri("http://localhost") .httpClient(httpClient) @@ -713,7 +701,7 @@ void testRejectsMissingPathParam() { @Test void testRejectsMultipleConsumesWithBody() { - assertThrows(RestResourceException.class, () -> + assertThatExceptionOfType(RestResourceException.class).isThrownBy(() -> RestClientBuilder.newBuilder() .baseUri("http://localhost") .httpClient(httpClient) @@ -723,28 +711,27 @@ void testRejectsMultipleConsumesWithBody() { @Test void testNullPathParamThrows() { final EchoPathApi api = proxy(EchoPathApi.class); - assertThrows(IllegalArgumentException.class, - () -> api.echoPath(null)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> api.echoPath(null)); } @Test void testQueryParamSpaceEncodedAsPercent20() { final EchoApi api = proxy(EchoApi.class); final String result = api.echo("hello world"); - assertEquals("hello%20world", result); + assertThat(result).isEqualTo("hello%20world"); } @Test void testQueryParamLiteralPlusEncodedAsPercent2B() { final EchoApi api = proxy(EchoApi.class); final String result = api.echo("a+b"); - assertEquals("a%2Bb", result); + assertThat(result).isEqualTo("a%2Bb"); } @Test void testStringResponseRespectsEntityCharset() { final CharsetApi api = proxy(CharsetApi.class); - assertEquals("caf\u00e9", api.get()); + assertThat(api.get()).isEqualTo("caf\u00e9"); } @Test @@ -754,30 +741,29 @@ void testResponseExceptionDefensiveCopy() { new RestClientResponseException(500, "error", original); original[0] = 99; final byte[] body = ex.getResponseBody(); - assertEquals(1, body[0]); + assertThat((int) body[0]).isEqualTo(1); body[1] = 99; - assertEquals(2, ex.getResponseBody()[1]); + assertThat((int) ex.getResponseBody()[1]).isEqualTo(2); } @Test void testStringBodyEncodedWithConsumesCharset() { final EchoBodyApi api = proxy(EchoBodyApi.class); final byte[] result = api.post("caf\u00e9"); - assertArrayEquals( - "caf\u00e9".getBytes(StandardCharsets.ISO_8859_1), result); + assertThat(result).containsExactly("caf\u00e9".getBytes(StandardCharsets.ISO_8859_1)); } @Test void testResponseExceptionNullBody() { final RestClientResponseException ex = new RestClientResponseException(204, "No Content", null); - assertNull(ex.getResponseBody()); + assertThat(ex.getResponseBody()).isNull(); } @Test void testEnumQueryParamUsesName() { final EnumQueryApi api = proxy(EnumQueryApi.class); - assertEquals("GREEN", api.echo(Color.GREEN)); + assertThat(api.echo(Color.GREEN)).isEqualTo("GREEN"); } } diff --git a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientH2Test.java b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientH2Test.java index 89cd1b7950..ca74a6ae0a 100644 --- a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientH2Test.java +++ b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientH2Test.java @@ -26,9 +26,8 @@ */ package org.apache.hc.client5.http.rest; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.net.InetAddress; @@ -176,33 +175,31 @@ private T proxy(final Class iface) { @Test void testStringGetOverH2() { final EchoApi api = proxy(EchoApi.class); - assertEquals("hello", api.echo("hello")); + assertThat(api.echo("hello")).isEqualTo("hello"); } @Test void testJsonPojoGetOverH2() { final JsonWidgetApi api = proxy(JsonWidgetApi.class); final Widget w = api.get(42); - assertEquals(42, w.id); - assertEquals("W-42", w.name); + assertThat(w.id).isEqualTo(42); + assertThat(w.name).isEqualTo("W-42"); } @Test void testJsonPojoPostOverH2() { final JsonWidgetApi api = proxy(JsonWidgetApi.class); final Widget w = api.create(new Widget(7, "Created")); - assertEquals(7, w.id); - assertEquals("Created", w.name); + assertThat(w.id).isEqualTo(7); + assertThat(w.name).isEqualTo("Created"); } @Test void testErrorResponseOverH2() { final JsonErrorApi api = proxy(JsonErrorApi.class); - final RestClientResponseException ex = assertThrows( - RestClientResponseException.class, - () -> api.getError(500)); - assertEquals(500, ex.getStatusCode()); - assertNotNull(ex.getResponseBody()); + final RestClientResponseException ex = assertThatExceptionOfType(RestClientResponseException.class).isThrownBy(() -> api.getError(500)).actual(); + assertThat(ex.getStatusCode()).isEqualTo(500); + assertThat(ex.getResponseBody()).isNotNull(); } @Test diff --git a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientIntegrationTest.java b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientIntegrationTest.java index 0f7585aa10..440a1d69f3 100644 --- a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientIntegrationTest.java +++ b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientIntegrationTest.java @@ -50,8 +50,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; class RestClientIntegrationTest { @@ -91,17 +90,17 @@ void executesRealRoundTripAgainstLocalServer() throws Exception { final Book created = client.createBook("abc-123", "en", "token-1", new Book(null, "HttpComponents in Action")); - assertNotNull(created); - assertEquals("abc-123", created.id); - assertEquals("HttpComponents in Action", created.title); - assertEquals("en", created.lang); + assertThat(created).isNotNull(); + assertThat(created.id).isEqualTo("abc-123"); + assertThat(created.title).isEqualTo("HttpComponents in Action"); + assertThat(created.lang).isEqualTo("en"); final Book fetched = client.getBook("abc-123", "en", "token-1"); - assertNotNull(fetched); - assertEquals("abc-123", fetched.id); - assertEquals("HttpComponents in Action", fetched.title); - assertEquals("en", fetched.lang); + assertThat(fetched).isNotNull(); + assertThat(fetched.id).isEqualTo("abc-123"); + assertThat(fetched.title).isEqualTo("HttpComponents in Action"); + assertThat(fetched.lang).isEqualTo("en"); } private void handleBooks(final HttpExchange exchange) throws IOException { diff --git a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientResponseTest.java b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientResponseTest.java index 86122485e5..64217853d4 100644 --- a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientResponseTest.java +++ b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestClientResponseTest.java @@ -54,11 +54,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; class RestClientResponseTest { @@ -95,15 +91,15 @@ void tearDown() throws Exception { void successResponseExposesStatusBodyAndHeaders() { final EchoApi api = build(); try (Response response = api.echo("abc")) { - assertEquals(200, response.getStatus()); - assertEquals(Response.Status.OK, response.getStatusInfo().toEnum()); - assertEquals("OK", response.getStatusInfo().getReasonPhrase()); - assertNotNull(response.getMediaType()); - assertEquals("application", response.getMediaType().getType()); - assertEquals("json", response.getMediaType().getSubtype()); - assertEquals("custom-value", response.getHeaderString("X-Custom")); - assertTrue(response.hasEntity()); - assertEquals("{\"id\":\"abc\"}", response.readEntity(String.class)); + assertThat(response.getStatus()).isEqualTo(200); + assertThat(response.getStatusInfo().toEnum()).isEqualTo(Response.Status.OK); + assertThat(response.getStatusInfo().getReasonPhrase()).isEqualTo("OK"); + assertThat(response.getMediaType()).isNotNull(); + assertThat(response.getMediaType().getType()).isEqualTo("application"); + assertThat(response.getMediaType().getSubtype()).isEqualTo("json"); + assertThat(response.getHeaderString("X-Custom")).isEqualTo("custom-value"); + assertThat(response.hasEntity()).isTrue(); + assertThat(response.readEntity(String.class)).isEqualTo("{\"id\":\"abc\"}"); } } @@ -112,7 +108,7 @@ void readEntityDecodesJsonPojo() { final EchoApi api = build(); try (Response response = api.echo("xyz")) { final Echo echo = response.readEntity(Echo.class); - assertEquals("xyz", echo.id); + assertThat(echo.id).isEqualTo("xyz"); } } @@ -121,9 +117,9 @@ void readEntityReturnsJsonNodeForJsonContent() { final EchoApi api = build(); try (Response response = api.echo("abc")) { final JsonNode node = response.readEntity(JsonNode.class); - assertNotNull(node); - assertTrue(node.isObject()); - assertEquals("abc", node.get("id").asText()); + assertThat(node).isNotNull(); + assertThat(node.isObject()).isTrue(); + assertThat(node.get("id").asText()).isEqualTo("abc"); } } @@ -135,9 +131,9 @@ void repeatedReadEntityReusesJsonTree() { final Echo pojo = response.readEntity(Echo.class); final JsonNode second = response.readEntity(JsonNode.class); - assertEquals("abc", pojo.id); - assertEquals("abc", first.get("id").asText()); - assertSame(first, second); + assertThat(pojo.id).isEqualTo("abc"); + assertThat(first.get("id").asText()).isEqualTo("abc"); + assertThat(second).isSameAs(first); } } @@ -149,9 +145,9 @@ void responseJsonEntityIsBackedByJsonNode() { final JsonNode node = OBJECT_MAPPER.createObjectNode().put("id", "abc"); try (Response response = new RestClientResponse(httpResponse, node, OBJECT_MAPPER)) { - assertSame(node, response.readEntity(JsonNode.class)); - assertEquals("abc", response.readEntity(Echo.class).id); - assertEquals("{\"id\":\"abc\"}", response.readEntity(String.class)); + assertThat(response.readEntity(JsonNode.class)).isSameAs(node); + assertThat(response.readEntity(Echo.class).id).isEqualTo("abc"); + assertThat(response.readEntity(String.class)).isEqualTo("{\"id\":\"abc\"}"); } } @@ -159,9 +155,9 @@ void responseJsonEntityIsBackedByJsonNode() { void errorResponsesAreReturnedNotThrown() { final EchoApi api = build(); try (Response response = api.failing()) { - assertEquals(418, response.getStatus()); - assertEquals(Response.Status.Family.CLIENT_ERROR, response.getStatusInfo().getFamily()); - assertEquals("nope", response.readEntity(String.class)); + assertThat(response.getStatus()).isEqualTo(418); + assertThat(response.getStatusInfo().getFamily()).isEqualTo(Response.Status.Family.CLIENT_ERROR); + assertThat(response.readEntity(String.class)).isEqualTo("nope"); } } @@ -169,9 +165,9 @@ void errorResponsesAreReturnedNotThrown() { void emptyBodyHasNoEntity() { final EchoApi api = build(); try (Response response = api.empty()) { - assertEquals(204, response.getStatus()); - assertFalse(response.hasEntity()); - assertTrue(response.getAllowedMethods().contains("GET")); + assertThat(response.getStatus()).isEqualTo(204); + assertThat(response.hasEntity()).isFalse(); + assertThat(response.getAllowedMethods().contains("GET")).isTrue(); } } @@ -180,8 +176,8 @@ void completionStageOfResponseDelivers2xx() throws Exception { final EchoApi api = build(); final CompletionStage stage = api.echoAsync("abc"); try (Response response = stage.toCompletableFuture().get(5, TimeUnit.SECONDS)) { - assertEquals(200, response.getStatus()); - assertEquals("abc", response.readEntity(Echo.class).id); + assertThat(response.getStatus()).isEqualTo(200); + assertThat(response.readEntity(Echo.class).id).isEqualTo("abc"); } } @@ -189,8 +185,8 @@ void completionStageOfResponseDelivers2xx() throws Exception { void completionStageOfResponseDeliversNon2xxAsValue() throws Exception { final EchoApi api = build(); try (Response response = api.failingAsync().toCompletableFuture().get(5, TimeUnit.SECONDS)) { - assertEquals(418, response.getStatus()); - assertEquals("nope", response.readEntity(String.class)); + assertThat(response.getStatus()).isEqualTo(418); + assertThat(response.readEntity(String.class)).isEqualTo("nope"); } } @@ -199,8 +195,8 @@ void completableFutureOfResponseDelivers2xx() throws Exception { final EchoApi api = build(); try (Response response = api.echoFuture("abc").get(5, TimeUnit.SECONDS)) { - assertEquals(200, response.getStatus()); - assertEquals("abc", response.readEntity(Echo.class).id); + assertThat(response.getStatus()).isEqualTo(200); + assertThat(response.readEntity(Echo.class).id).isEqualTo("abc"); } } diff --git a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestInvocationHandlerTest.java b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestInvocationHandlerTest.java index 8f2772724b..d670a8b423 100644 --- a/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestInvocationHandlerTest.java +++ b/httpclient5-jakarta-rest-client/src/test/java/org/apache/hc/client5/http/rest/RestInvocationHandlerTest.java @@ -26,7 +26,8 @@ */ package org.apache.hc.client5.http.rest; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.jupiter.api.Test; @@ -34,9 +35,9 @@ class RestInvocationHandlerTest { @Test void testParamToStringBasicTypes() { - assertEquals("42", RestInvocationHandler.paramToString(42)); - assertEquals("true", RestInvocationHandler.paramToString(true)); - assertEquals("hello", RestInvocationHandler.paramToString("hello")); + assertThat(RestInvocationHandler.paramToString(42)).isEqualTo("42"); + assertThat(RestInvocationHandler.paramToString(true)).isEqualTo("true"); + assertThat(RestInvocationHandler.paramToString("hello")).isEqualTo("hello"); } enum Color { RED, GREEN, BLUE } @@ -52,13 +53,13 @@ public String toString() { @Test void testParamToStringEnumUsesName() { - assertEquals("RED", RestInvocationHandler.paramToString(Color.RED)); - assertEquals("GREEN", RestInvocationHandler.paramToString(Color.GREEN)); + assertThat(RestInvocationHandler.paramToString(Color.RED)).isEqualTo("RED"); + assertThat(RestInvocationHandler.paramToString(Color.GREEN)).isEqualTo("GREEN"); } @Test void testParamToStringEnumIgnoresOverriddenToString() { - assertEquals("ALPHA", RestInvocationHandler.paramToString(OverriddenToString.ALPHA)); + assertThat(RestInvocationHandler.paramToString(OverriddenToString.ALPHA)).isEqualTo("ALPHA"); } }