mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestServerSocketChannel.java
@Test
    public void testActivateWakeLock() throws InterruptedException
    {
        // mock the input
        Socket socket = mock(Socket.class);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);

        // mock the message listener
        SocketMessageListener socketMessageListener = mock(SocketMessageListener.class);
        when(m_ListenerInstance.getInstance()).thenReturn(socketMessageListener);
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                return null;
            }
        }).when(socketMessageListener).run();

        when(m_RemoteSettings.isPreventSleepModeEnabled()).thenReturn(true);

        // activate the component
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);

        // verify wake lock is activated
        verify(m_WakeLock).activate();

        // all new channels start out as unknown
        assertThat(m_SUT.getStatus(), is(ChannelStatus.Unknown));
    }
/**
     * Verify that the wake lock is activated when enabled by the remote settings.
     */
Verify that the wake lock is activated when enabled by the remote settings.
Verify that the wake lock is activated when enabled by the remote settings .
@Test
    public void testActivateWakeLock() throws InterruptedException
    {
        Socket socket = mock(Socket.class);
        SocketAddress socketAddress = mock(SocketAddress.class);
        when(socketAddress.toString()).thenReturn(REMOTE_SOCKET_ADDR);
        when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
        SocketMessageListener socketMessageListener = mock(SocketMessageListener.class);
        when(m_ListenerInstance.getInstance()).thenReturn(socketMessageListener);
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                return null;
            }
        }).when(socketMessageListener).run();
        when(m_RemoteSettings.isPreventSleepModeEnabled()).thenReturn(true);
        Map<String, Object> props = new HashMap<String, Object>();
        props.put(ServerSocketChannel.SOCKET_PROP_KEY, socket);
        m_SUT.activate(props);
        verify(m_WakeLock).activate();
        assertThat(m_SUT.getStatus(), is(ChannelStatus.Unknown));
    }
@ Test public void testActivateWakeLock ( ) throws InterruptedException { Socket socket = mock ( Socket . class ) ; SocketAddress socketAddress = mock ( SocketAddress . class ) ; when ( socketAddress . toString ( ) ) . thenReturn ( REMOTE_SOCKET_ADDR ) ; when ( socket . getRemoteSocketAddress ( ) ) . thenReturn ( socketAddress ) ; SocketMessageListener socketMessageListener = mock ( SocketMessageListener . class ) ; when ( m_ListenerInstance . getInstance ( ) ) . thenReturn ( socketMessageListener ) ; doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( InvocationOnMock invocation ) throws Throwable { return null ; } } ) . when ( socketMessageListener ) . run ( ) ; when ( m_RemoteSettings . isPreventSleepModeEnabled ( ) ) . thenReturn ( true ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( ServerSocketChannel . SOCKET_PROP_KEY , socket ) ; m_SUT . activate ( props ) ; verify ( m_WakeLock ) . activate ( ) ; assertThat ( m_SUT . getStatus ( ) , is ( ChannelStatus . Unknown ) ) ; }
Verify that the wake lock is activated when enabled by the remote settings.
Verify that the wake lock is activated when enabled by the remote settings .
// mock the input // mock the message listener // activate the component // verify wake lock is activated // all new channels start out as unknown