@Test
public void testRead() throws Exception {

    BufferedPullDataSource pds = spy(new BufferedPullDataSource());
    pds.remoteReader = new DataInputStream(new MockInputStream(BufferedPullDataSource.MAX_BUFFER * 5));
    pds.remoteWriter = new ByteArrayOutputStream(); // dummy output stream
    pds._buffer = new byte[BufferedPullDataSource.MAX_BUFFER];
    pds.opened = true;
    pds.size = BufferedPullDataSource.MAX_BUFFER * 5;
    byte buffer[] = new byte[BufferedPullDataSource.MAX_BUFFER];
    // read a single byte, which should force the buffer to fill
    int size = 1;
    int read = pds.read(0, buffer, 0, 1);
    assertEquals(size, read);
    assertEquals(new String(data, 0, size), new String(buffer, 0, size));
    verify(pds, times(1)).fillBuffer(eq(0l));
    // now read a bunch of other single byte reads, which should NOT force a buffer re-fill
    read = pds.read(0, buffer, 1, 1);
    assertEquals(size, read);
    assertEquals(new String(data, 1, size), new String(buffer, 1, size));
    verify(pds, times(1)).fillBuffer(eq(0l));
    // now read some data that is outside the buffer range, and it should force a re-read
    read = pds.read(BufferedPullDataSource.MAX_BUFFER * 2, buffer, 0, 1);
    assertEquals(size, read);
    //assertEquals(((BufferedPullDataSource.MAX_BUFFER*2)%10)+'0', buffer[0]);
    verify(pds, times(1)).fillBuffer(eq(BufferedPullDataSource.MAX_BUFFER * 2l));
}