From 3e1a9fbfdff9bdf998d481cdc670c1235624f5c1 Mon Sep 17 00:00:00 2001 From: Jakob Frank Date: Tue, 10 Sep 2024 22:55:54 +0200 Subject: [PATCH] chore: #sonarlint --- pom.xml | 1 + .../utils/logging/LoggingContextTest.java | 68 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index b8829c0..26d6e4e 100644 --- a/pom.xml +++ b/pom.xml @@ -226,6 +226,7 @@ 3.8.0 ${java.version} + ${java.version} diff --git a/slf4j/src/test/java/io/redlink/utils/logging/LoggingContextTest.java b/slf4j/src/test/java/io/redlink/utils/logging/LoggingContextTest.java index 20f90db..c6d7c61 100644 --- a/slf4j/src/test/java/io/redlink/utils/logging/LoggingContextTest.java +++ b/slf4j/src/test/java/io/redlink/utils/logging/LoggingContextTest.java @@ -151,23 +151,22 @@ void testWrapInCopyRunable() throws Throwable { final String value2 = UUID.randomUUID().toString(); MDC.put("mdc", value); - try (ExecutorService executor = Executors.newSingleThreadExecutor()) { - try (LoggingContext ctx = LoggingContext.create()) { - MDC.put("mdc", value2); - - final Future future = executor.submit( - ctx.wrapInCopy(() -> { - assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); - MDC.put("mdc", UUID.randomUUID().toString()); - })); - assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); - future.get(); - assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); - } catch (ExecutionException e) { - throw e.getCause(); - } finally { - executor.shutdownNow(); - } + final ExecutorService executor = Executors.newSingleThreadExecutor(); + try (LoggingContext ctx = LoggingContext.create()) { + MDC.put("mdc", value2); + + final Future future = executor.submit( + ctx.wrapInCopy(() -> { + assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); + MDC.put("mdc", UUID.randomUUID().toString()); + })); + assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); + future.get(); + assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); + } catch (ExecutionException e) { + throw e.getCause(); + } finally { + executor.shutdownNow(); } } @@ -177,24 +176,23 @@ void testWrapInCopyCallable() throws Throwable { final String value2 = UUID.randomUUID().toString(); MDC.put("mdc", value); - try (ExecutorService executor = Executors.newSingleThreadExecutor()) { - try (LoggingContext ctx = LoggingContext.create()) { - MDC.put("mdc", value2); - - final Future future = executor.submit( - ctx.wrapInCopy((Callable) () -> { - assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); - MDC.put("mdc", UUID.randomUUID().toString()); - return "hello"; - })); - assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); - future.get(); - assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); - } catch (ExecutionException e) { - throw e.getCause(); - } finally { - executor.shutdownNow(); - } + final ExecutorService executor = Executors.newSingleThreadExecutor(); + try (LoggingContext ctx = LoggingContext.create()) { + MDC.put("mdc", value2); + + final Future future = executor.submit( + ctx.wrapInCopy((Callable) () -> { + assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); + MDC.put("mdc", UUID.randomUUID().toString()); + return "hello"; + })); + assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); + future.get(); + assertThat(MDC.get("mdc"), CoreMatchers.is(value2)); + } catch (ExecutionException e) { + throw e.getCause(); + } finally { + executor.shutdownNow(); } }