mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestServerSocketChannel.java
@Test
    public void testGetHost()
    {
        // mock the socket and its InetAddress as it contains the hostname used by the method
        Socket socket = mock(Socket.class);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        InetAddress inetAddress = mock(InetAddress.class);
        when(socket.getInetAddress()).thenReturn(inetAddress);
        when(inetAddress.getHostName()).thenReturn("test-host");
        
        // activate the component
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        
        assertThat(m_SUT.getHost(), is("test-host"));
    }
/**
     * Verify host returned is the one associated with the incoming socket. 
     */
Verify host returned is the one associated with the incoming socket.
Verify host returned is the one associated with the incoming socket .
@Test
    public void testGetHost()
    {
        Socket socket = mock(Socket.class);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        InetAddress inetAddress = mock(InetAddress.class);
        when(socket.getInetAddress()).thenReturn(inetAddress);
        when(inetAddress.getHostName()).thenReturn("test-host");
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        assertThat(m_SUT.getHost(), is("test-host"));
    }
@ Test public void testGetHost ( ) { Socket socket = mock ( Socket . class ) ; SocketAddress socketAddress = mock ( SocketAddress . class ) ; when ( socketAddress . toString ( ) ) . thenReturn ( REMOTE_SOCKET_ADDR ) ; when ( socket . getRemoteSocketAddress ( ) ) . thenReturn ( socketAddress ) ; InetAddress inetAddress = mock ( InetAddress . class ) ; when ( socket . getInetAddress ( ) ) . thenReturn ( inetAddress ) ; when ( inetAddress . getHostName ( ) ) . thenReturn ( "test-host" ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( ServerSocketChannel . SOCKET_PROP_KEY , socket ) ; m_SUT . activate ( props ) ; assertThat ( m_SUT . getHost ( ) , is ( "test-host" ) ) ; }
Verify host returned is the one associated with the incoming socket.
Verify host returned is the one associated with the incoming socket .
// mock the socket and its InetAddress as it contains the hostname used by the method // activate the component