mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestServerSocketChannel.java
@Test
    public void testTrySendMessageFailure() throws IOException
    {
        // mock the socket that will throw exception when trying to send
        Socket socket = mock(Socket.class);
        OutputStream outStream = new OutputStream()
        {
            @Override
            public void write(int b) throws IOException
            {
                throw new IOException();
            }
        };
        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
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        
        TerraHarvestMessage message = createBaseMessage();
        
        // replay
        boolean result = m_SUT.trySendMessage(message);
        assertThat(result, is(false));
    }
/**
     * Verify method returns false if socket throws exception
     */
Verify method returns false if socket throws exception
Verify method returns false if socket throws exception
@Test
    public void testTrySendMessageFailure() throws IOException
    {
        Socket socket = mock(Socket.class);
        OutputStream outStream = new OutputStream()
        {
            @Override
            public void write(int b) throws IOException
            {
                throw new IOException();
            }
        };
        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);
        TerraHarvestMessage message = createBaseMessage();
        boolean result = m_SUT.trySendMessage(message);
        assertThat(result, is(false));
    }
@ Test public void testTrySendMessageFailure ( ) throws IOException { Socket socket = mock ( Socket . class ) ; OutputStream outStream = new OutputStream ( ) { @ Override public void write ( int b ) throws IOException { throw new IOException ( ) ; } } ; 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 ) ; TerraHarvestMessage message = createBaseMessage ( ) ; boolean result = m_SUT . trySendMessage ( message ) ; assertThat ( result , is ( false ) ) ; }
Verify method returns false if socket throws exception
Verify method returns false if socket throws exception
// mock the socket that will throw exception when trying to send // activate method expects a connected socket to be passed in // replay