Raid1Device implements Device { public void write(final long address, final byte[] data) throws Exception { if (blockCount == -1) { throw new IllegalStateException("You first have to open the Device!"); } long blocks = data.length / blockSize; if (address < 0 || address + blocks > blockCount) { long adr = address < 0 ? address : address + blocks - 1; throw new IllegalArgumentException("Address " + adr + " out of range."); } if (data.length % blockSize != 0) { throw new IllegalArgumentException("Number of bytes is not a multiple of the blocksize!"); } barrier = new CyclicBarrier(devices.length + 1); for (int i = 0; i < devices.length; i++) { executor.execute(new WriteThread(devices[i], (int)address, data)); } barrier.await(); } Raid1Device(final Device[] initDevices); void close(); int getBlockSize(); String getName(); long getBlockCount(); void open(); void read(final long address, final byte[] data); void write(final long address, final byte[] data);  }
@Test(expected = IllegalArgumentException.class) public void testWriteAddressToLow() throws Exception { address = -1; device.write(address, testData); }
@Test(expected = IllegalArgumentException.class) public void testWriteIllegalSize() throws Exception { address = 0; byte[] data = new byte[1]; randomGenerator.nextBytes(data); device.write(address, data); }
@Test(expected = IllegalStateException.class) public void testWriteNotOpened() throws Exception { Device newDevice = new Raid1Device(jSCSIDevices); address = 0; newDevice.write(address, testData); }