@Test(timeout = 10000)
public void read() throws Exception {

    Path tmpFile = tempFile();
    Files.write(tmpFile, new byte[]{1, 2, 3});
    PipeChannel channel = DefaultPipeChannel.open(tmpFile);
    ByteBuffer bb = ByteBuffer.allocate(5);
    int n = channel.read(bb).get();
    assertThat(n).isEqualTo(3);
    assertThat(bb.array()).as("simple read operation").containsExactly((byte) 1, (byte) 2, (byte) 3, (byte) 0, (byte) 0);
    bb = ByteBuffer.allocate(5);
    bb.limit(2);
    // Note: we test here implicitly that the targeted file is always read from position 0.
    n = channel.read(bb).get();
    assertThat(n).isEqualTo(2);
    assertThat(bb.array()).as("read with limit set").containsExactly((byte) 1, (byte) 2, (byte) 0, (byte) 0, (byte) 0);
    bb = ByteBuffer.allocate(5);
    bb.position(2);
    bb.limit(4);
    n = channel.read(bb).get();
    assertThat(n).isEqualTo(2);
    assertThat(bb.array()).containsExactly((byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 0)
            .as("read with position and limit set");
}