From b630a45c81811c957c24bac52855dc46f13351c9 Mon Sep 17 00:00:00 2001 From: Benedikt Waldvogel Date: Thu, 22 Aug 2024 10:48:29 +0200 Subject: [PATCH] Use pattern variables where possible --- src/main/java/de/cronn/testutils/ExecutorServiceUtils.java | 6 ++---- .../java/de/cronn/testutils/spring/ResetClockExtension.java | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/cronn/testutils/ExecutorServiceUtils.java b/src/main/java/de/cronn/testutils/ExecutorServiceUtils.java index 38218b0..4ef7e88 100644 --- a/src/main/java/de/cronn/testutils/ExecutorServiceUtils.java +++ b/src/main/java/de/cronn/testutils/ExecutorServiceUtils.java @@ -70,8 +70,7 @@ private static boolean shutdown(ExecutorService executorService, String executor if (success) { log.info("Finished shutdown of '{}'", executorServiceName); } else { - if (executorService instanceof ThreadPoolExecutor) { - ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService; + if (executorService instanceof ThreadPoolExecutor threadPoolExecutor) { log.warn("Shutdown of '{}' timed out after {} ms. Active tasks: {}", executorServiceName, timeoutMillis, threadPoolExecutor.getActiveCount()); } else { log.warn("Shutdown of '{}' timed out after {} ms.", executorServiceName, timeoutMillis); @@ -81,8 +80,7 @@ private static boolean shutdown(ExecutorService executorService, String executor } private static void clearQueue(ExecutorService executorService, String executorServiceName) { - if (executorService instanceof ThreadPoolExecutor) { - ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService; + if (executorService instanceof ThreadPoolExecutor threadPoolExecutor) { BlockingQueue queue = threadPoolExecutor.getQueue(); if (!queue.isEmpty()) { int queueSize = queue.size(); diff --git a/src/main/java/de/cronn/testutils/spring/ResetClockExtension.java b/src/main/java/de/cronn/testutils/spring/ResetClockExtension.java index 44d8779..e124d35 100644 --- a/src/main/java/de/cronn/testutils/spring/ResetClockExtension.java +++ b/src/main/java/de/cronn/testutils/spring/ResetClockExtension.java @@ -45,8 +45,8 @@ public static boolean hasDeclaredMethodOrder(ExtensionContext context) { protected void resetClock(ExtensionContext context) { ApplicationContext applicationContext = SpringExtension.getApplicationContext(context); Clock clock = applicationContext.getBean(Clock.class); - if (clock instanceof TestClock) { - ((TestClock) clock).reset(); + if (clock instanceof TestClock testClock) { + testClock.reset(); } }