CollectionMultipartFormDataMessageBodyWriter implements MessageBodyWriter<Collection<OutputItem>> { @Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (Collection.class.isAssignableFrom(type) && genericType instanceof ParameterizedType) { ParameterizedType t = (ParameterizedType)genericType; Type[] ta = t.getActualTypeArguments(); return ta.length == 1 && ta[0] instanceof Class && OutputItem.class.isAssignableFrom((Class<?>)ta[0]); } return false; } CollectionMultipartFormDataMessageBodyWriter(@Context Providers providers);   CollectionMultipartFormDataMessageBodyWriter(MultipartFormDataWriter multipartFormDataWriter); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Collection<OutputItem> items, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(Collection<OutputItem> items, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream);  }
@Test public void isWriteableForListOfOutputItems() throws Exception { Class<List> type = List.class; ParameterizedType genericType = ParameterizedTypeImpl.newParameterizedType(List.class, OutputItem.class); assertTrue(collectionMultipartFormDataMessageBodyWriter.isWriteable(type, genericType, new Annotation[0], null)); }
@Test public void isWriteableForSetOfOutputItems() throws Exception { Class<Set> type = Set.class; ParameterizedType genericType = ParameterizedTypeImpl.newParameterizedType(Set.class, OutputItem.class); assertTrue(collectionMultipartFormDataMessageBodyWriter.isWriteable(type, genericType, new Annotation[0], null)); }
@Test public void isWriteableForAnyCollectionOfOutputItems() throws Exception { Class<Collection> type = Collection.class; ParameterizedType genericType = ParameterizedTypeImpl.newParameterizedType(Collection.class, OutputItem.class); assertTrue(collectionMultipartFormDataMessageBodyWriter.isWriteable(type, genericType, new Annotation[0], null)); }
@Test public void isNotWriteableForAnyCollectionOfOtherTypeThanOutputItems() throws Exception { Class<Collection> type = Collection.class; ParameterizedType genericType = ParameterizedTypeImpl.newParameterizedType(Collection.class, String.class); assertFalse(collectionMultipartFormDataMessageBodyWriter.isWriteable(type, genericType, new Annotation[0], null)); }
@Test public void isNotWriteableWhenGenericTypeIsNotAvailable() throws Exception { Class<Collection> type = Collection.class; assertFalse(collectionMultipartFormDataMessageBodyWriter.isWriteable(type, null, new Annotation[0], null)); }