@Test
public void testToByteArray() throws IOException {

	// Null input stream
	Assert.assertNull(StreamUtil.toByteArray(null));
	// Return unsafe byte array
	byte[] bytes = new byte[StreamUtil.BUFFER_SIZE + 1];
	Random random = new Random();
	random.nextBytes(bytes);
	UnsyncByteArrayInputStream unsyncByteArrayInputStream =
		new UnsyncByteArrayInputStream(bytes);
	Assert.assertArrayEquals(
		bytes, StreamUtil.toByteArray(unsyncByteArrayInputStream));
	// Return safe byte array
	unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(bytes) {
		@Override
		public int available() {
			return 0;
		}
	};
	Assert.assertArrayEquals(
		bytes, StreamUtil.toByteArray(unsyncByteArrayInputStream));
}