@Test public void testDisconnectWithCustomSoLingerOption() throws Exception { Socket socket = mockSocket(); when(socketFactory.createSocket(anyString(), anyInt())).thenReturn(socket); BaseChannel rawChannel = new RawChannel(); rawChannel.setSocketFactory(socketFactory); rawChannel.setSoLinger(true, 0); rawChannel.connect(); rawChannel.disconnect(); verify(socket).setSoLinger(true, 0); verify(socket).close(); verify(socket, never()).shutdownOutput(); // this does not make sense when sending a TCP RST down the socket assertTrue(rawChannel.isSoLingerOn()); assertEquals(0, rawChannel.getSoLingerSeconds()); }