edu.udayton.udri.asset.canon.ipcamera/test/edu/udayton/udri/asset/canon/ipcamera/TestIpCameraAsset.java
@Test(expected = CommandExecutionException.class)
    public void testGetPanIoException2() throws IOException, InterruptedException, AssetException
    {
        m_SUT.onActivate();
        final byte[] propsBytes = 
                new byte[]{'c', '.', '1', '.', 'p', 'a', 'n', ':', '=', '9', '4', '.', '4', '\n',
                           'c', '.', '1', '.', 't', 'i', 'l', 't', ':', '=', '1', '0', '0', '\n'};
        InputStream input = new InputStream()
        {
            private int m_Counter;
            private int m_ReadBytesCounter;
            @Override
            public int read() throws IOException
            {
                int returnVal = -1;
                if (m_Counter < propsBytes.length)
                {
                    returnVal = propsBytes[m_Counter];
                    m_Counter++;
                }
                return returnVal;
            }
            
            @Override
            public int read(byte[] b) throws IOException
            {
                int bytesRead = -1;
                if (m_ReadBytesCounter == 0)
                {
                    System.arraycopy(propsBytes, 0, b, 0, propsBytes.length);
                    bytesRead = propsBytes.length;
                }
                m_ReadBytesCounter++;
                return bytesRead;
            }
        };
        GetPanTiltCommand fakeGetPanTilt = new GetPanTiltCommand();
        URLConnection urlCon = mock(URLConnection.class);
        when(m_Context.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATED);
        when(m_UrlUtil.getConnection(any(URL.class))).thenReturn(urlCon).thenReturn(urlCon);
        when(m_UrlUtil.getInputStream(any(URLConnection.class))).thenReturn(input).thenThrow(new IOException());
        m_SUT.onExecuteCommand(fakeGetPanTilt);  
    }
//Catches the IO exception in the handleGetTilt when trying to create an Input Stream
Catches the IO exception in the handleGetTilt when trying to create an Input Stream
Catches the IO exception in the handleGetTilt when trying to create an Input Stream
@Test(expected = CommandExecutionException.class)
    public void testGetPanIoException2() throws IOException, InterruptedException, AssetException
    {
        m_SUT.onActivate();
        final byte[] propsBytes = 
                new byte[]{'c', '.', '1', '.', 'p', 'a', 'n', ':', '=', '9', '4', '.', '4', '\n',
                           'c', '.', '1', '.', 't', 'i', 'l', 't', ':', '=', '1', '0', '0', '\n'};
        InputStream input = new InputStream()
        {
            private int m_Counter;
            private int m_ReadBytesCounter;
            @Override
            public int read() throws IOException
            {
                int returnVal = -1;
                if (m_Counter < propsBytes.length)
                {
                    returnVal = propsBytes[m_Counter];
                    m_Counter++;
                }
                return returnVal;
            }
            @Override
            public int read(byte[] b) throws IOException
            {
                int bytesRead = -1;
                if (m_ReadBytesCounter == 0)
                {
                    System.arraycopy(propsBytes, 0, b, 0, propsBytes.length);
                    bytesRead = propsBytes.length;
                }
                m_ReadBytesCounter++;
                return bytesRead;
            }
        };
        GetPanTiltCommand fakeGetPanTilt = new GetPanTiltCommand();
        URLConnection urlCon = mock(URLConnection.class);
        when(m_Context.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATED);
        when(m_UrlUtil.getConnection(any(URL.class))).thenReturn(urlCon).thenReturn(urlCon);
        when(m_UrlUtil.getInputStream(any(URLConnection.class))).thenReturn(input).thenThrow(new IOException());
        m_SUT.onExecuteCommand(fakeGetPanTilt);  
    }
@ Test ( expected = CommandExecutionException . class ) public void testGetPanIoException2 ( ) throws IOException , InterruptedException , AssetException { m_SUT . onActivate ( ) ; final byte [ ] propsBytes = new byte [ ] { 'c' , '.' , '1' , '.' , 'p' , 'a' , 'n' , ':' , '=' , '9' , '4' , '.' , '4' , '\n' , 'c' , '.' , '1' , '.' , 't' , 'i' , 'l' , 't' , ':' , '=' , '1' , '0' , '0' , '\n' } ; InputStream input = new InputStream ( ) { private int m_Counter ; private int m_ReadBytesCounter ; @ Override public int read ( ) throws IOException { int returnVal = - 1 ; if ( m_Counter < propsBytes . length ) { returnVal = propsBytes [ m_Counter ] ; m_Counter ++ ; } return returnVal ; } @ Override public int read ( byte [ ] b ) throws IOException { int bytesRead = - 1 ; if ( m_ReadBytesCounter == 0 ) { System . arraycopy ( propsBytes , 0 , b , 0 , propsBytes . length ) ; bytesRead = propsBytes . length ; } m_ReadBytesCounter ++ ; return bytesRead ; } } ; GetPanTiltCommand fakeGetPanTilt = new GetPanTiltCommand ( ) ; URLConnection urlCon = mock ( URLConnection . class ) ; when ( m_Context . getActiveStatus ( ) ) . thenReturn ( AssetActiveStatus . ACTIVATED ) ; when ( m_UrlUtil . getConnection ( any ( URL . class ) ) ) . thenReturn ( urlCon ) . thenReturn ( urlCon ) ; when ( m_UrlUtil . getInputStream ( any ( URLConnection . class ) ) ) . thenReturn ( input ) . thenThrow ( new IOException ( ) ) ; m_SUT . onExecuteCommand ( fakeGetPanTilt ) ; }
Catches the IO exception in the handleGetTilt when trying to create an Input Stream
Catches the IO exception in the handleGetTilt when trying to create an Input Stream