mil.dod.th.remote.client/test/mil/dod/th/remote/client/impl/TestMessageListenerServiceImpl.java
@SuppressWarnings({"unchecked", "rawtypes"})
    @Test
    public void testRecvWithCallbackException() throws IOException, InterruptedException
    {
        doThrow(new RuntimeException("callback error"))
            .when(m_MessageCallback).handleMessage(Mockito.any(RemoteMessage.class));

        RemoteMessage<?> mockedMessage = mock(RemoteMessage.class);
        when(mockedMessage.getNamespace()).thenReturn(Namespace.Base);
        when(m_Converter.convertMessage(Mockito.any(TerraHarvestMessage.class)))
            .thenReturn((RemoteMessage)mockedMessage);

        m_SUT.addRemoteChannel(SRC_ID, m_InputStream, m_ChannelCallback);

        m_SUT.registerCallback(Namespace.Base, m_MessageCallback);

        // Include second callback to verify exception from above doesn't crash receiving thread
        MessageListenerCallback<?> secondCallback = mock(MessageListenerCallback.class);
        m_SUT.registerCallback(Namespace.Base, secondCallback);

        // Send a message
        createTestMessage().writeDelimitedTo(m_OutputStream);

        // Wait for processing to complete
        verify(secondCallback, timeout(2000)).handleMessage((RemoteMessage)mockedMessage);
    }
/**
     * Verify that exceptions thrown by callbacks do not cause the listening thread to crash.
     */
Verify that exceptions thrown by callbacks do not cause the listening thread to crash.
Verify that exceptions thrown by callbacks do not cause the listening thread to crash .
@SuppressWarnings({"unchecked", "rawtypes"})
    @Test
    public void testRecvWithCallbackException() throws IOException, InterruptedException
    {
        doThrow(new RuntimeException("callback error"))
            .when(m_MessageCallback).handleMessage(Mockito.any(RemoteMessage.class));
        RemoteMessage<?> mockedMessage = mock(RemoteMessage.class);
        when(mockedMessage.getNamespace()).thenReturn(Namespace.Base);
        when(m_Converter.convertMessage(Mockito.any(TerraHarvestMessage.class)))
            .thenReturn((RemoteMessage)mockedMessage);
        m_SUT.addRemoteChannel(SRC_ID, m_InputStream, m_ChannelCallback);
        m_SUT.registerCallback(Namespace.Base, m_MessageCallback);
        MessageListenerCallback<?> secondCallback = mock(MessageListenerCallback.class);
        m_SUT.registerCallback(Namespace.Base, secondCallback);
        createTestMessage().writeDelimitedTo(m_OutputStream);
        verify(secondCallback, timeout(2000)).handleMessage((RemoteMessage)mockedMessage);
    }
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) @ Test public void testRecvWithCallbackException ( ) throws IOException , InterruptedException { doThrow ( new RuntimeException ( "callback error" ) ) . when ( m_MessageCallback ) . handleMessage ( Mockito . any ( RemoteMessage . class ) ) ; RemoteMessage < ? > mockedMessage = mock ( RemoteMessage . class ) ; when ( mockedMessage . getNamespace ( ) ) . thenReturn ( Namespace . Base ) ; when ( m_Converter . convertMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( ( RemoteMessage ) mockedMessage ) ; m_SUT . addRemoteChannel ( SRC_ID , m_InputStream , m_ChannelCallback ) ; m_SUT . registerCallback ( Namespace . Base , m_MessageCallback ) ; MessageListenerCallback < ? > secondCallback = mock ( MessageListenerCallback . class ) ; m_SUT . registerCallback ( Namespace . Base , secondCallback ) ; createTestMessage ( ) . writeDelimitedTo ( m_OutputStream ) ; verify ( secondCallback , timeout ( 2000 ) ) . handleMessage ( ( RemoteMessage ) mockedMessage ) ; }
Verify that exceptions thrown by callbacks do not cause the listening thread to crash.
Verify that exceptions thrown by callbacks do not cause the listening thread to crash .
// Include second callback to verify exception from above doesn't crash receiving thread // Send a message // Wait for processing to complete