Signal { public static synchronized SignalHandler handle(final Signal signal, final SignalHandler signalHandler) throws IllegalArgumentException { Objects.requireNonNull(signal); Objects.requireNonNull(signalHandler); return wrap(sun.misc.Signal.handle(unwrap(signal), wrap(signalHandler))); } Signal(String name); int getNumber(); String getName(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); static synchronized SignalHandler handle(final Signal signal,
      final SignalHandler signalHandler); static void raise(Signal signal);  }
@Test public void handleWrapsSunHandler() { final sun.misc.SignalHandler sunHandler = mock(sun.misc.SignalHandler.class); final sun.misc.Signal sunSignal = new sun.misc.Signal("INT"); final sun.misc.SignalHandler originalSunHandler = sun.misc.Signal.handle(sunSignal, sunHandler); try { final Signal geodeSignal = new Signal("INT"); final SignalHandler geodeHandler = signal -> { }; final SignalHandler originalGeodeHandler = Signal.handle(geodeSignal, geodeHandler); try { assertThat(originalGeodeHandler).isNotNull().isInstanceOf(Signal.SunSignalHandler.class); assertThat(((Signal.SunSignalHandler) originalGeodeHandler).signalHandler) .isSameAs(sunHandler); originalGeodeHandler.handle(geodeSignal); verify(sunHandler).handle(sunSignal); verifyNoMoreInteractions(sunHandler); } finally { assertThat(Signal.handle(geodeSignal, originalGeodeHandler)).isSameAs(geodeHandler); } } finally { assertThat(sun.misc.Signal.handle(sunSignal, originalSunHandler)).isSameAs(sunHandler); } }
@Test public void handleNullThrowsException() { assertThatThrownBy(() -> Signal.handle(new Signal("INT"), null)) .isInstanceOf(NullPointerException.class); assertThatThrownBy(() -> Signal.handle(null, signal -> { })) .isInstanceOf(NullPointerException.class); }