Search in sources :

Example 11 with MockTcpConnectionThread

use of com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread in project 360-Engine-for-Android by 360.

the class ResponseReaderThreadTest method testSetInputstream.

@MediumTest
public void testSetInputstream() {
    DecoderThread decoder = new DecoderThread();
    MockTcpConnectionThread mockThread = new MockTcpConnectionThread(decoder, null);
    MockResponseReaderThread respReader = new MockResponseReaderThread(mockThread, decoder, // QUICKFIX: Not sure about this value
    null);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 });
    respReader.setInputStream(new BufferedInputStream(bais));
    DataInputStream dis = (DataInputStream) respReader.getInputStream();
    assertNotNull(dis);
    // let's test all the bytes...
    if (null != dis) {
        boolean areBytesCorrect = true;
        for (int i = 1; i < 6; i++) {
            try {
                int j = dis.readByte();
                if (-1 == j) {
                    fail("Unexpected end of the DataInputStream");
                    areBytesCorrect = false;
                } else if (i != j) {
                    fail("Characters differ: i: " + i + " vs. j: " + j);
                    areBytesCorrect = false;
                }
            } catch (IOException e) {
            }
        }
        assertTrue(areBytesCorrect);
    }
    respReader.setInputStream(null);
    assertNull(respReader.getInputStream());
}
Also used : DecoderThread(com.vodafone360.people.service.transport.DecoderThread) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) MockTcpConnectionThread(com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

MediumTest (android.test.suitebuilder.annotation.MediumTest)11 DecoderThread (com.vodafone360.people.service.transport.DecoderThread)10 Suppress (android.test.suitebuilder.annotation.Suppress)7 IOException (java.io.IOException)6 MockTcpConnectionThread (com.vodafone360.people.tests.service.transport.tcp.conn_less.hb_tests.MockTcpConnectionThread)5 BufferedInputStream (java.io.BufferedInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1