From 870426408b1e4b75d2e19adcccf53a974818270c Mon Sep 17 00:00:00 2001 From: Abdelhak Zaaim Date: Fri, 15 Nov 2024 11:07:03 +0100 Subject: [PATCH] Refactor assertions to use `assertThat` with appropriate matchers --- .../interceptor/InterceptorRuntimeTest.java | 15 ++++++++------- .../inject/tools/ActivatorCreatorDefaultTest.java | 5 ++--- .../microprofile/scheduling/InvalidStateTest.java | 7 ++++--- .../functional/requestscopecdi/SecretTest.java | 5 ++--- .../io/helidon/webclient/tests/HttpProxyTest.java | 5 ++--- .../Http2ErrorHandlingWithOutputStreamTest.java | 11 +++++------ .../helidon/webserver/http/ErrorHandlersTest.java | 3 +-- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/inject/tests/resources-inject/src/test/java/io/helidon/inject/tests/inject/interceptor/InterceptorRuntimeTest.java b/inject/tests/resources-inject/src/test/java/io/helidon/inject/tests/inject/interceptor/InterceptorRuntimeTest.java index 994397aadb0..740113e467c 100644 --- a/inject/tests/resources-inject/src/test/java/io/helidon/inject/tests/inject/interceptor/InterceptorRuntimeTest.java +++ b/inject/tests/resources-inject/src/test/java/io/helidon/inject/tests/inject/interceptor/InterceptorRuntimeTest.java @@ -59,7 +59,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; class InterceptorRuntimeTest { @@ -91,9 +90,10 @@ void createNoArgBasedInterceptorSource() throws Exception { assertThat(file.exists(), is(true)); String java = Files.readString(file.toPath()); String expected = loadStringFromResource("expected/ximpl-interceptor._java_"); - assertEquals( - expected.replaceFirst("#DATE#", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))), - java); + assertThat( + java, + is(expected.replaceFirst("#DATE#", Integer.toString(Calendar.getInstance().get(Calendar.YEAR)))) + ); } @Test @@ -104,9 +104,10 @@ void createInterfaceBasedInterceptorSource() throws Exception { assertThat(file.exists(), is(true)); String java = Files.readString(file.toPath()); String expected = loadStringFromResource("expected/yimpl-interceptor._java_"); - assertEquals( - expected.replaceFirst("#DATE#", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))), - java); + assertThat( + java, + is(expected.replaceFirst("#DATE#", Integer.toString(Calendar.getInstance().get(Calendar.YEAR)))) + ); } @Test diff --git a/inject/tools/src/test/java/io/helidon/inject/tools/ActivatorCreatorDefaultTest.java b/inject/tools/src/test/java/io/helidon/inject/tools/ActivatorCreatorDefaultTest.java index 493766d4f19..c4e87021084 100644 --- a/inject/tools/src/test/java/io/helidon/inject/tools/ActivatorCreatorDefaultTest.java +++ b/inject/tools/src/test/java/io/helidon/inject/tools/ActivatorCreatorDefaultTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2023, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -67,7 +66,7 @@ void codegenHelloActivator() { .build(); ToolsException te = assertThrows(ToolsException.class, () -> activatorCreator.createModuleActivators(req)); - assertEquals("Failed in create", te.getMessage()); + assertThat(te.getMessage(), is("Failed in create")); ActivatorCreatorRequest req2 = ActivatorCreatorRequest.builder() .serviceTypeNames(Collections.singletonList(TypeName.create(HelloInjectionWorldImpl.class))) diff --git a/microprofile/scheduling/src/test/java/io/helidon/microprofile/scheduling/InvalidStateTest.java b/microprofile/scheduling/src/test/java/io/helidon/microprofile/scheduling/InvalidStateTest.java index 15d87dddb86..07b0cf1cd22 100644 --- a/microprofile/scheduling/src/test/java/io/helidon/microprofile/scheduling/InvalidStateTest.java +++ b/microprofile/scheduling/src/test/java/io/helidon/microprofile/scheduling/InvalidStateTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,8 @@ import org.junit.jupiter.api.Test; import org.opentest4j.AssertionFailedError; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.jupiter.api.Assertions.fail; public class InvalidStateTest { @@ -124,7 +125,7 @@ void assertDeploymentException(Class expected, Map