/** * Tests the ability to write a single value. * * @throws Exception If one got thrown. */ @Test public void testWriteSingleValue() throws Exception { val expectedData = newArray(); @Cleanup val s = createInstance(newArray()); AssertExtensions.assertThrows( "write() allowed writing at negative position.", () -> s.write(1, -1), ex -> ex instanceof IndexOutOfBoundsException); AssertExtensions.assertThrows( "write() allowed writing overflow position.", () -> s.write(1, expectedData.length), ex -> ex instanceof IndexOutOfBoundsException); for (int i = 0; i < expectedData.length; i += 3) { expectedData[i] = (byte) i; s.write(i, i); } byte[] writtenData = getData(s); Assert.assertArrayEquals("Unexpected Stream contents.", expectedData, writtenData); }
public void testWriteArray() throws Exception { int writeLength = 10; byte[] expectedData = newArray(); @Cleanup val s = createInstance(newArray()); AssertExtensions.assertThrows( "write() allowed writing at negative position.", if (canGrow()) { byte[] writtenData = getData(s); Assert.assertArrayEquals("Unexpected Stream contents.", expectedData, writtenData);
public void testSubStream() throws Exception { int writeLength = 10; byte[] expectedData = newArray(); @Cleanup val s = createInstance(newArray()); AssertExtensions.assertThrows( "subStream() allowed writing at negative position.", byte[] writtenData = getData(s); Assert.assertArrayEquals("Unexpected Stream contents.", expectedData, writtenData);