### Question:
MemorySnapshot implements Snapshot { @Override @Nonnull public SnapshotChunk readData(int offset, int length) { if (offset < 0 || offset > data.length) { throw new IndexOutOfBoundsException("offset " + offset + " out of bound"); } int bufferLength = Math.min(data.length - offset, length); byte[] buffer = new byte[bufferLength]; System.arraycopy(data, offset, buffer, 0, bufferLength); return new SnapshotChunk(buffer, offset + length >= this.data.length); } MemorySnapshot(int lastIncludedIndex, int lastIncludedTerm);  MemorySnapshot(int lastIncludedIndex, int lastIncludedTerm, byte[] data, Set<NodeEndpoint> lastConfig); @Override int getLastIncludedIndex(); @Override int getLastIncludedTerm(); @Nonnull @Override Set<NodeEndpoint> getLastConfig(); @Override long getDataSize(); byte[] getData(); @Override @Nonnull SnapshotChunk readData(int offset, int length); @Override @Nonnull InputStream getDataStream(); @Override void close(); @Override String toString();  }### Answer:
@Test public void testReadEmpty() { MemorySnapshot snapshot = new MemorySnapshot(0, 0); snapshot.readData(0, 10); }
@Test public void testRead1() { MemorySnapshot snapshot = new MemorySnapshot(0, 0, "foo".getBytes(), Collections.emptySet()); SnapshotChunk chunk1 = snapshot.readData(0, 2); Assert.assertArrayEquals(new byte[]{'f', 'o'}, chunk1.toByteArray()); Assert.assertFalse(chunk1.isLastChunk()); SnapshotChunk lastChunk = snapshot.readData(2, 2); Assert.assertArrayEquals(new byte[]{'o'}, lastChunk.toByteArray()); Assert.assertTrue(lastChunk.isLastChunk()); }
@Test public void testRead2() { MemorySnapshot snapshot = new MemorySnapshot(0, 0, "foo,".getBytes(), Collections.emptySet()); Assert.assertArrayEquals(new byte[]{'f', 'o'}, snapshot.readData(0, 2).toByteArray()); Assert.assertArrayEquals(new byte[]{'o', ','}, snapshot.readData(2, 2).toByteArray()); }