title: Mock openInputStream read method
body: <p>I am reading chunks of data from openInputStream and wanted to mock it's read method.</p>
  
  <pre><code> final byte[] testFileData = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x64, 0x61, 0x74, 0x61, 0x0d, 0x0a};
  
   CloudBlob cloudBlob = this.getCloudBlobContainer().getBlobReferenceFromServer(blobName);
  
      ByteArrayOutputStream blobStream = new ByteArrayOutputStream();
  
      try (final InputStream inputStream =  cloudBlob.openInputStream()) {
  
          //Read 4MB chunks of data 
          byte[] bufferToRead = new byte[4 * 1024 *1024];
          int bytesRead = inputStream.read(bufferToRead );
  
          while (bytesRead &gt; 0) {
              //Add only the total number of bytes read to Bytearrayoutputstream
              blobStream.write(bufferToRead, 0, bytesRead);
              bytesRead = inputStream.read(bufferToRead);                
          }
      } `
  </code></pre>
  
  <p>I did mock InputStream but finding difficulties mocking it's read method because it accepts the buffer as reference and copy byte array to it after reading it.</p>
  
  <pre><code> @Mock
  private BlobInputStream inputStream;
  
  
         // Mock
          when(cloudBlobContainer.getBlobReferenceFromServer(anyString())).thenReturn(cloudBlob);
          when(cloudBlob.openInputStream()).thenReturn(inputStream);  
  </code></pre>