BlobHelper { public static void serializeTo(Object obj, HeapDataOutputStream hdos) throws IOException { final int startBytes = hdos.size(); final long start = startSerialization(); DataSerializer.writeObject(obj, hdos); endSerialization(start, hdos.size() - startBytes); }  static byte[] serializeToBlob(Object obj); static byte[] serializeToBlob(Object obj, KnownVersion version); static void serializeTo(Object obj, HeapDataOutputStream hdos); static Object deserializeBlob(byte[] blob); static Object deserializeBlob(byte[] blob, KnownVersion version, ByteArrayDataInput in); static @Unretained Object deserializeOffHeapBlob(StoredObject blob); static Object deserializeBuffer(ByteArrayDataInput in, int numBytes);  }
@Test public void serializeMapToStreamWritesMapAsBytes() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); serializeTo(this.mapWithTwoEntries, hdos); assertThat(hdos.toByteArray()).isNotNull().isEqualTo(bytesOfMap); }
@Test public void serializeNullToStreamWritesNullAsBytes() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); serializeTo(null, hdos); assertThat(hdos.toByteArray()).isNotNull().isEqualTo(this.bytesOfNull); }
@Test public void serializeToNullNullThrowsNullPointerException() throws Exception { assertThatThrownBy(() -> serializeTo(null, null)) .isExactlyInstanceOf(NullPointerException.class); }
@Test public void serializeToNullStreamThrowsNullPointerException() throws Exception { assertThatThrownBy(() -> serializeTo(this.mapWithTwoEntries, null)) .isExactlyInstanceOf(NullPointerException.class); }
@Test public void serializeUnserializableToStreamThrowsNotSerializableException() throws Exception { HeapDataOutputStream hdos = createHeapDataOutputStream(); assertThatThrownBy(() -> serializeTo(new Object(), hdos)) .isExactlyInstanceOf(NotSerializableException.class).hasMessage(Object.class.getName()); }