edu.udayton.udri.asset.canon.ipcamera/test/edu/udayton/udri/asset/canon/ipcamera/TestIpCameraAsset.java
@Test(expected = CommandExecutionException.class)
    public void testGetPanIoException1() 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).thenThrow(new IOException());
        when(m_UrlUtil.getInputStream(any(URLConnection.class))).thenReturn(input);
        m_SUT.onExecuteCommand(fakeGetPanTilt);  
    }
//Catches the IO exception in the handleGetPan when trying to create an URL connection
Catches the IO exception in the handleGetPan when trying to create an URL connection
Catches the IO exception in the handleGetPan when trying to create an URL connection
@Test(expected = CommandExecutionException.class)
    public void testGetPanIoException1() 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).thenThrow(new IOException());
        when(m_UrlUtil.getInputStream(any(URLConnection.class))).thenReturn(input);
        m_SUT.onExecuteCommand(fakeGetPanTilt);  
    }
@ Test ( expected = CommandExecutionException . class ) public void testGetPanIoException1 ( ) 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 ) . thenThrow ( new IOException ( ) ) ; when ( m_UrlUtil . getInputStream ( any ( URLConnection . class ) ) ) . thenReturn ( input ) ; m_SUT . onExecuteCommand ( fakeGetPanTilt ) ; }
Catches the IO exception in the handleGetPan when trying to create an URL connection
Catches the IO exception in the handleGetPan when trying to create an URL connection