mil.dod.th.ose.shared/test/mil/dod/th/ose/shared/TestScheduledExceptionLoggingThreadPool.java
@Test
    public void testHandleThrownExceptionScheduled() throws InterruptedException, ExecutionException
    {
        Exception throwMe = new Exception("A purple people eater attacked.");
        Exception t = Mockito.spy(throwMe);
        Callable<String> r = new ExceptionThrower(t);
        Future<String> future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
            //expecting exception
        }
        
        //verify logging
        Mockito.verify(m_Log, Mockito.timeout(25)).error(t, "Executor threw an exception");
                
        //test for CancellationException
        CancellationException canceled = new CancellationException("A cancellation exception message.");
        CancellationException ce = Mockito.spy(canceled);
        r = new ExceptionThrower(ce);
        future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
            //expecting exception
        }
        
        //verify logging
        Mockito.verify(m_Log, Mockito.timeout(25)).error(ce, "Executor threw an exception");
        
        //test for ExecutionException
        IOException ioExcept = new IOException("An IO exception message");
        IOException io = Mockito.spy(ioExcept);
        ExecutionException eExcept = new ExecutionException(io);
        ExecutionException ee = Mockito.spy(eExcept);
        r = new ExceptionThrower(ee);
        future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
            //expecting exception
        }
        
        //verify logging
        Mockito.verify(m_Log, Mockito.timeout(25)).error(ee, "Executor threw an exception"); 
        
        //test for InterruptedException
        InterruptedException ieExcept = new InterruptedException("An interrupted exception message.");
        InterruptedException ie = Mockito.spy(ieExcept);
        r = new ExceptionThrower(ie);
        future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
            //expecting exception
        }
        
        //verify logging
        Mockito.verify(m_Log, Mockito.timeout(25)).error(ie, "Executor threw an exception"); 
    }
/**
     * Test method for exception handling in scheduled thread pools.
     */
Test method for exception handling in scheduled thread pools.
Test method for exception handling in scheduled thread pools .
@Test
    public void testHandleThrownExceptionScheduled() throws InterruptedException, ExecutionException
    {
        Exception throwMe = new Exception("A purple people eater attacked.");
        Exception t = Mockito.spy(throwMe);
        Callable<String> r = new ExceptionThrower(t);
        Future<String> future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
        }
        Mockito.verify(m_Log, Mockito.timeout(25)).error(t, "Executor threw an exception");
        CancellationException canceled = new CancellationException("A cancellation exception message.");
        CancellationException ce = Mockito.spy(canceled);
        r = new ExceptionThrower(ce);
        future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
        }
        Mockito.verify(m_Log, Mockito.timeout(25)).error(ce, "Executor threw an exception");
        IOException ioExcept = new IOException("An IO exception message");
        IOException io = Mockito.spy(ioExcept);
        ExecutionException eExcept = new ExecutionException(io);
        ExecutionException ee = Mockito.spy(eExcept);
        r = new ExceptionThrower(ee);
        future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
        }
        Mockito.verify(m_Log, Mockito.timeout(25)).error(ee, "Executor threw an exception"); 
        InterruptedException ieExcept = new InterruptedException("An interrupted exception message.");
        InterruptedException ie = Mockito.spy(ieExcept);
        r = new ExceptionThrower(ie);
        future = m_SUT.schedule(r, 0, TimeUnit.SECONDS);
        try
        {
            future.get();
        }
        catch (Exception e)
        {
        }
        Mockito.verify(m_Log, Mockito.timeout(25)).error(ie, "Executor threw an exception"); 
    }
@ Test public void testHandleThrownExceptionScheduled ( ) throws InterruptedException , ExecutionException { Exception throwMe = new Exception ( "A purple people eater attacked." ) ; Exception t = Mockito . spy ( throwMe ) ; Callable < String > r = new ExceptionThrower ( t ) ; Future < String > future = m_SUT . schedule ( r , 0 , TimeUnit . SECONDS ) ; try { future . get ( ) ; } catch ( Exception e ) { } Mockito . verify ( m_Log , Mockito . timeout ( 25 ) ) . error ( t , "Executor threw an exception" ) ; CancellationException canceled = new CancellationException ( "A cancellation exception message." ) ; CancellationException ce = Mockito . spy ( canceled ) ; r = new ExceptionThrower ( ce ) ; future = m_SUT . schedule ( r , 0 , TimeUnit . SECONDS ) ; try { future . get ( ) ; } catch ( Exception e ) { } Mockito . verify ( m_Log , Mockito . timeout ( 25 ) ) . error ( ce , "Executor threw an exception" ) ; IOException ioExcept = new IOException ( "An IO exception message" ) ; IOException io = Mockito . spy ( ioExcept ) ; ExecutionException eExcept = new ExecutionException ( io ) ; ExecutionException ee = Mockito . spy ( eExcept ) ; r = new ExceptionThrower ( ee ) ; future = m_SUT . schedule ( r , 0 , TimeUnit . SECONDS ) ; try { future . get ( ) ; } catch ( Exception e ) { } Mockito . verify ( m_Log , Mockito . timeout ( 25 ) ) . error ( ee , "Executor threw an exception" ) ; InterruptedException ieExcept = new InterruptedException ( "An interrupted exception message." ) ; InterruptedException ie = Mockito . spy ( ieExcept ) ; r = new ExceptionThrower ( ie ) ; future = m_SUT . schedule ( r , 0 , TimeUnit . SECONDS ) ; try { future . get ( ) ; } catch ( Exception e ) { } Mockito . verify ( m_Log , Mockito . timeout ( 25 ) ) . error ( ie , "Executor threw an exception" ) ; }
Test method for exception handling in scheduled thread pools.
Test method for exception handling in scheduled thread pools .
//expecting exception //verify logging //test for CancellationException //expecting exception //verify logging //test for ExecutionException //expecting exception //verify logging //test for InterruptedException //expecting exception //verify logging