Unit test for mocking of octet stream and fix to the code