EscSpiUtils { public static EnhancedMimeType mimeType(@NotNull final SerializerRegistry registry, @NotNull final List<CommonEvent> commonEvents) { Contract.requireArgNotNull("registry", registry); Contract.requireArgNotNull("commonEvents", commonEvents); EnhancedMimeType mimeType = null; for (final CommonEvent commonEvent : commonEvents) { final Serializer serializer = registry.getSerializer(new SerializedDataType(commonEvent.getDataType().asBaseType())); if (mimeType == null) { mimeType = serializer.getMimeType(); } else { if (!mimeType.equals(serializer.getMimeType())) { return null; } } } return mimeType; } 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 testMimeTypeSame() { final SimpleSerializerDeserializerRegistry registry = new SimpleSerializerDeserializerRegistry(); final String type = "TypeX"; final SerializedDataType serType = new SerializedDataType(type); final TypeName eventType = new TypeName(type); registry.addSerializer(serType, dummySerializer("text/plain")); final List<CommonEvent> events = new ArrayList<>(); events.add(new SimpleCommonEvent(new EventId(), eventType, "One")); final EnhancedMimeType mimeType = EscSpiUtils.mimeType(registry, events); assertThat(mimeType.toString()).isEqualTo("text/plain"); }
@Test public void testMimeTypeDifferent() { final SimpleSerializerDeserializerRegistry registry = new SimpleSerializerDeserializerRegistry(); final String typeA = "TypeA"; final SerializedDataType serTypeA = new SerializedDataType(typeA); final TypeName eventTypeA = new TypeName(typeA); registry.addSerializer(serTypeA, dummySerializer("text/plain")); final String typeB = "TypeB"; final SerializedDataType serTypeB = new SerializedDataType(typeB); final TypeName eventTypeB = new TypeName(typeB); registry.addSerializer(serTypeB, dummySerializer("application/xml")); final List<CommonEvent> events = new ArrayList<>(); events.add(new SimpleCommonEvent(new EventId(), eventTypeA, "One")); events.add(new SimpleCommonEvent(new EventId(), eventTypeB, "<Other/>")); final EnhancedMimeType mimeType = EscSpiUtils.mimeType(registry, events); assertThat(mimeType).isNull(); }