From 1e088e6783a9bdaaa007acd5ccd54bd23add00ce Mon Sep 17 00:00:00 2001 From: Dmitry Vyazelenko <696855+vyazelenko@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:32:13 +0200 Subject: [PATCH] [Java] Fix formatting. --- .../java/org/agrona/concurrent/SigInt.java | 9 +++-- .../org/agrona/concurrent/SigIntTest.java | 34 ++++++++++++------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/agrona/src/main/java/org/agrona/concurrent/SigInt.java b/agrona/src/main/java/org/agrona/concurrent/SigInt.java index 723ab73d9..55d62a49f 100644 --- a/agrona/src/main/java/org/agrona/concurrent/SigInt.java +++ b/agrona/src/main/java/org/agrona/concurrent/SigInt.java @@ -22,17 +22,20 @@ /** * Utility to allow the registration of a SIGINT handler that hides the unsupported {@link Signal} class. */ -public class SigInt { +public class SigInt +{ /** * Register a task to be run when a SIGINT is received. * * @param task to run on reception of the signal. */ - public static void register(final Runnable task) { + public static void register(final Runnable task) + { register("INT", task); } - static void register(final String signalName, final Runnable task) { + static void register(final String signalName, final Runnable task) + { Objects.requireNonNull(task); Signal.handle(new Signal(signalName), (signal) -> task.run()); } diff --git a/agrona/src/test/java/org/agrona/concurrent/SigIntTest.java b/agrona/src/test/java/org/agrona/concurrent/SigIntTest.java index d7301603a..790db94fe 100644 --- a/agrona/src/test/java/org/agrona/concurrent/SigIntTest.java +++ b/agrona/src/test/java/org/agrona/concurrent/SigIntTest.java @@ -28,24 +28,28 @@ import static org.junit.jupiter.api.Assertions.assertThrowsExactly; import static org.mockito.Mockito.*; -class SigIntTest { +class SigIntTest +{ @Test - void throwsNullPointerExceptionIfRunnableIsNull() { + void throwsNullPointerExceptionIfRunnableIsNull() + { assertThrowsExactly(NullPointerException.class, () -> SigInt.register(null)); } @ParameterizedTest - @ValueSource(strings = {"INT", "TERM"}) - void shouldReplaceExistingSignalHandler(final String name) throws InterruptedException { + @ValueSource(strings = { "INT", "TERM" }) + void shouldReplaceExistingSignalHandler(final String name) throws InterruptedException + { final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = - Thread.getDefaultUncaughtExceptionHandler(); + Thread.getDefaultUncaughtExceptionHandler(); final Signal signal = new Signal(name); final SignalHandler originalHandler = Signal.handle(signal, sig -> {}); - try { + try + { final CountDownLatch executed = new CountDownLatch(1); final Thread.UncaughtExceptionHandler exceptionHandler = mock(Thread.UncaughtExceptionHandler.class); - doAnswer((Answer) invocation -> + doAnswer((Answer)invocation -> { executed.countDown(); return null; @@ -71,19 +75,23 @@ void shouldReplaceExistingSignalHandler(final String name) throws InterruptedExc inOrder.verifyNoMoreInteractions(); verifyNoInteractions(oldHandler); - } finally { + } + finally + { Thread.setDefaultUncaughtExceptionHandler(defaultUncaughtExceptionHandler); Signal.handle(signal, originalHandler); } } @ParameterizedTest - @ValueSource(strings = {"INT"}) - void shouldReplaceExistingSignalHandlerNoException(final String name) throws InterruptedException { + @ValueSource(strings = { "INT" }) + void shouldReplaceExistingSignalHandlerNoException(final String name) throws InterruptedException + { final Signal signal = new Signal(name); final SignalHandler originalHandler = Signal.handle(signal, sig -> {}); - try { + try + { final SignalHandler oldHandler = mock(SignalHandler.class); Signal.handle(signal, oldHandler); @@ -94,7 +102,9 @@ void shouldReplaceExistingSignalHandlerNoException(final String name) throws Int executed.await(); verifyNoInteractions(oldHandler); - } finally { + } + finally + { Signal.handle(signal, originalHandler); } }