RandomAccessStorageModule implements IStorageModule { @Override public final int checkBounds (final long logicalBlockAddress, final int transferLengthInBlocks) { if (logicalBlockAddress < 0 || logicalBlockAddress >= sizeInBlocks) return 1; if (transferLengthInBlocks < 0 || logicalBlockAddress + transferLengthInBlocks > sizeInBlocks) return 2; return 0; } RandomAccessStorageModule(final long sizeInBlocks, final File file); @Override void read(byte[] bytes, long storageIndex); @Override void write(byte[] bytes, long storageIndex); @Override final long getSizeInBlocks(); @Override final int checkBounds(final long logicalBlockAddress, final int transferLengthInBlocks); final void close(); @Override int getBlockSize(); static synchronized final IStorageModule open(final File file, final long storageLength, final boolean create, Class<? extends IStorageModule> kind); static boolean recursiveDelete(final File pFile);  }
@Test public void testCheckBounds0 () { int result = module.checkBounds(0, 2); assertEquals(0, result); result = module.checkBounds(1, 1); assertEquals(0, result); result = module.checkBounds(1, 1); assertEquals(0, result); result = module.checkBounds(0, 0); assertEquals(0, result); }
@Test public void testCheckBounds1 () { int result = module.checkBounds(-1, 1); assertEquals(1, result); result = module.checkBounds(2, 1); assertEquals(0, result); }
@Test public void testCheckBounds2 () { int result = module.checkBounds(0, 3); assertEquals(0, result); result = module.checkBounds(0, -1); assertEquals(2, result); }