PosixSysTerminal extends AbstractPosixTerminal { @Override public SignalHandler handle(Signal signal, SignalHandler handler) { SignalHandler prev = super.handle(signal, handler); if (prev != handler) { if (handler == SignalHandler.SIG_DFL) { Signals.registerDefault(signal.name()); } else { Signals.register(signal.name(), () -> raise(signal)); } } return prev; } PosixSysTerminal(String name, String type, Pty pty, Charset encoding,
                            boolean nativeSignals, SignalHandler signalHandler); @Override SignalHandler handle(Signal signal, SignalHandler handler); NonBlockingReader reader(); PrintWriter writer(); @Override InputStream input(); @Override OutputStream output();  }
@Test public void testNativeSignalsRegister() throws Exception { Pty pty = EasyMock.createNiceMock(Pty.class); EasyMock.expect(pty.getAttr()).andReturn(new Attributes()).anyTimes(); EasyMock.expect(pty.getSlaveInput()).andReturn(new ByteArrayInputStream(new byte[0])).anyTimes(); EasyMock.expect(pty.getSlaveOutput()).andReturn(new ByteArrayOutputStream()).anyTimes(); EasyMock.replay(pty); try (PosixSysTerminal terminal = new PosixSysTerminal( "name", "ansi", pty,null, true, SignalHandler.SIG_DFL)) { assertEquals(Signal.values().length, terminal.nativeHandlers.size()); SignalHandler prev = terminal.handle(Signal.INT, s -> {}); assertEquals(Signal.values().length, terminal.nativeHandlers.size()); terminal.handle(Signal.INT, prev); assertEquals(Signal.values().length, terminal.nativeHandlers.size()); } }