mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestServerSocketChannel.java
@Test
    public void testDeactivation() throws IOException, InterruptedException
    {
        // mock the socket and input stream that will be used to send the message
        Socket socket = mock(Socket.class);
        OutputStream outStream = mock(OutputStream.class);
        when(socket.getOutputStream()).thenReturn(outStream);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        
        // activate method expects a connected socket to be passed in and remote channel
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        
        m_SUT.deactivate();
        verify(outStream).close();
        verify(socket).close();
        verify(m_ListenerInstance).dispose();
        verify(m_SenderInstance).dispose();
        verify(m_WakeLock).delete();
        
        // this time have both methods throw exception, should still complete deactivation and each one called
        doThrow(new IOException()).when(socket).close();
        doThrow(new IOException()).when(outStream).close();
        
        m_SUT.deactivate();
        //verify
        verify(outStream, times(2)).close();
        verify(socket, times(2)).close();        
        verify(m_ListenerInstance, times(2)).dispose();
    }
/**
     * Verify socket and output stream is closed on deactivation.
     * 
     * Verify message listener is disposed
     */
Verify socket and output stream is closed on deactivation.

Verify message listener is disposed
Verify socket and output stream is closed on deactivation . Verify message listener is disposed
@Test
    public void testDeactivation() throws IOException, InterruptedException
    {
        Socket socket = mock(Socket.class);
        OutputStream outStream = mock(OutputStream.class);
        when(socket.getOutputStream()).thenReturn(outStream);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        m_SUT.deactivate();
        verify(outStream).close();
        verify(socket).close();
        verify(m_ListenerInstance).dispose();
        verify(m_SenderInstance).dispose();
        verify(m_WakeLock).delete();
        doThrow(new IOException()).when(socket).close();
        doThrow(new IOException()).when(outStream).close();
        m_SUT.deactivate();
        verify(outStream, times(2)).close();
        verify(socket, times(2)).close();        
        verify(m_ListenerInstance, times(2)).dispose();
    }
@ Test public void testDeactivation ( ) throws IOException , InterruptedException { Socket socket = mock ( Socket . class ) ; OutputStream outStream = mock ( OutputStream . class ) ; when ( socket . getOutputStream ( ) ) . thenReturn ( outStream ) ; SocketAddress socketAddress = mock ( SocketAddress . class ) ; when ( socketAddress . toString ( ) ) . thenReturn ( REMOTE_SOCKET_ADDR ) ; when ( socket . getRemoteSocketAddress ( ) ) . thenReturn ( socketAddress ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( ServerSocketChannel . SOCKET_PROP_KEY , socket ) ; m_SUT . activate ( props ) ; m_SUT . deactivate ( ) ; verify ( outStream ) . close ( ) ; verify ( socket ) . close ( ) ; verify ( m_ListenerInstance ) . dispose ( ) ; verify ( m_SenderInstance ) . dispose ( ) ; verify ( m_WakeLock ) . delete ( ) ; doThrow ( new IOException ( ) ) . when ( socket ) . close ( ) ; doThrow ( new IOException ( ) ) . when ( outStream ) . close ( ) ; m_SUT . deactivate ( ) ; verify ( outStream , times ( 2 ) ) . close ( ) ; verify ( socket , times ( 2 ) ) . close ( ) ; verify ( m_ListenerInstance , times ( 2 ) ) . dispose ( ) ; }
Verify socket and output stream is closed on deactivation.
Verify socket and output stream is closed on deactivation .
// mock the socket and input stream that will be used to send the message // activate method expects a connected socket to be passed in and remote channel // this time have both methods throw exception, should still complete deactivation and each one called //verify