From aea7cf3e741ca3367504c189e634d8a422f303c1 Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Sun, 4 Feb 2024 17:19:17 +0100 Subject: [PATCH] tests: update test for jdk21 (#128) --- .../cdi/test/ErrorDataServiceJdk17Test.java | 66 +++++++++++++++++++ .../log/cdi/test/ErrorDataServiceTest.java | 7 +- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceJdk17Test.java diff --git a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceJdk17Test.java b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceJdk17Test.java new file mode 100644 index 0000000..710d3e0 --- /dev/null +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceJdk17Test.java @@ -0,0 +1,66 @@ +package org.tkit.quarkus.log.cdi.test; + +import static org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException.DUMMY_ERROR_NUMBER; + +import jakarta.inject.Inject; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException; +import org.tkit.quarkus.log.cdi.test.app.ErrorDataService; +import org.tkit.quarkus.log.cdi.test.app.ErrorWrapperService; + +import io.quarkus.test.QuarkusUnitTest; + +@EnabledForJreRange(max = JRE.JAVA_17) +public class ErrorDataServiceJdk17Test extends AbstractTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(ErrorDataService.class, ErrorWrapperService.class, DummyLogFriendlyException.class) + .addAsResource("default.properties", "application.properties")); + + @Inject + ErrorDataService service; + + @Inject + ErrorWrapperService wrapper; + + @Test + public void error1Test() { + Assertions.assertThrows(RuntimeException.class, () -> service.error1("Error")); + assertLogs() + .assertLines(92) + .assertContains(0, + "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(Error) throw java.lang.RuntimeException: Error"); + } + + @Test + public void error2Test() { + Assertions.assertThrows(RuntimeException.class, () -> service.error2()); + assertLogs().assertContains(0, + DUMMY_ERROR_NUMBER + + " ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error2() throw org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException"); + } + + @Test + public void noStacktraceTest() { + Assertions.assertThrows(RuntimeException.class, () -> service.noStacktrace()); + assertLogs().assertLines(1) + .assertContains(0, + "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) noStacktrace() throw java.lang.RuntimeException: Error1"); + } + + @Test + public void wrapperTest() { + Assertions.assertThrows(RuntimeException.class, () -> wrapper.wrapperMethod("WrapperError")); + assertLogs().assertLines(106) + .assertContains(0, + "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(WrapperError) throw java.lang.RuntimeException: WrapperError"); + } + +} diff --git a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java index 7835d2b..3df3aab 100644 --- a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java @@ -6,6 +6,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException; import org.tkit.quarkus.log.cdi.test.app.ErrorDataService; @@ -13,6 +15,7 @@ import io.quarkus.test.QuarkusUnitTest; +@EnabledForJreRange(min = JRE.JAVA_21) public class ErrorDataServiceTest extends AbstractTest { @RegisterExtension @@ -31,7 +34,7 @@ public class ErrorDataServiceTest extends AbstractTest { public void error1Test() { Assertions.assertThrows(RuntimeException.class, () -> service.error1("Error")); assertLogs() - .assertLines(92) + .assertLines(90) .assertContains(0, "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(Error) throw java.lang.RuntimeException: Error"); } @@ -55,7 +58,7 @@ public void noStacktraceTest() { @Test public void wrapperTest() { Assertions.assertThrows(RuntimeException.class, () -> wrapper.wrapperMethod("WrapperError")); - assertLogs().assertLines(106) + assertLogs().assertLines(104) .assertContains(0, "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(WrapperError) throw java.lang.RuntimeException: WrapperError"); }