EscSpiUtils { @Nullable public static SerializedData serialize(@NotNull final SerializerRegistry registry, @NotNull final SerializedDataType type, @Nullable final Object data) { if (data == null) { return null; } Contract.requireArgNotNull("registry", registry); Contract.requireArgNotNull("type", type); final Serializer serializer = registry.getSerializer(type); return new SerializedData(type, serializer.getMimeType(), serializer.marshal(data, type)); } private  EscSpiUtils(); @Nullable static SerializedData serialize(@NotNull final SerializerRegistry registry, @NotNull final SerializedDataType type,
            @Nullable final Object data); @NotNull static T deserialize(@NotNull final DeserializerRegistry registry, @NotNull final SerializedData data); static EnhancedMimeType mimeType(@NotNull final SerializerRegistry registry, @NotNull final List<CommonEvent> commonEvents); static List<T> asList(final T[] array); static boolean eventsEqual(@Nullable final List<CommonEvent> eventsA, @Nullable final List<CommonEvent> eventsB); static EscMeta createEscMeta(@NotNull final SerializerRegistry registry, @NotNull final EnhancedMimeType targetContentType,
            @Nullable final CommonEvent commonEvent); static String nodeToString(final Node node); static JsonbSerializer<?>[] createEscJsonbSerializers(); static JsonbSerializer<?>[] joinJsonbSerializers(final JsonbSerializer<?>[] serializersA,
            final JsonbSerializer<?>... serializersB); static JsonbSerializer<?>[] joinJsonbSerializerArrays(final JsonbSerializer<?>[]... serializerArrays); static JsonbDeserializer<?>[] createEscJsonbDeserializers(); static JsonbDeserializer<?>[] joinJsonbDeserializers(final JsonbDeserializer<?>[] deserializersA,
            final JsonbDeserializer<?>... deserializersB); static JsonbDeserializer<?>[] joinJsonbDeserializerArrays(final JsonbDeserializer<?>[]... deserializerArrays);  }
@Test public void testSerializeNull() { final SerializerRegistry registry = new SimpleSerializerDeserializerRegistry(); final SerializedDataType type = new SerializedDataType("whatever"); final SerializedData result = EscSpiUtils.serialize(registry, type, null); assertThat(result).isNull(); }
@Test public void testSerializeOK() { final SimpleSerializerDeserializerRegistry registry = new SimpleSerializerDeserializerRegistry(); final SerializedDataType type = new SerializedDataType("whatever"); registry.addSerializer(type, dummySerializer("text/plain")); final String data = "My Data"; final SerializedData result = EscSpiUtils.serialize(registry, type, data); assertThat(result.getType()).isEqualTo(type); assertThat(result.getRaw()).isEqualTo(data.getBytes()); }
@Test public void testSerializeNoSerializerFound() { final SerializerRegistry registry = new SimpleSerializerDeserializerRegistry(); final SerializedDataType type = new SerializedDataType("whatever"); final Object data = "My Data"; try { EscSpiUtils.serialize(registry, type, data); } catch (final IllegalArgumentException ex) { assertThat(ex.getMessage()).isEqualTo("No serializer found for: whatever"); } }