I am mocking the socket class and ObjectInputstream class. Here is a test case which is giving me
java.io.StreamCorruptedException
The test case is as follows:
public void test_tryPush() throws IOException {
ByteArrayInputStream inside = new ByteArrayInputStream("hey".getBytes());
Mockito.when(socket.getInputStream()).thenReturn(inside);
input = new ObjectInputStream(socket.getInputStream());
assertSame(inside, socket.getInputStream());
}
If I do not delcare the input object of ObjectInputStream class the test passes.
But the test above gives the following trace.
Running tests
Test running started
java.io.StreamCorruptedException
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2109)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:372)
at tests.MockingTest.test_tryPush(MockingTest.java:113)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
Finish
Please can anybody tell me what is going wrong here. I am trying to mock the client side socket.
Aucun commentaire:
Enregistrer un commentaire