@Test
public void writesCollectionOfOutputItems() throws Exception {

    OutputItem item1 = anOutputItem().withName("item1").withEntity("item1 entity").withMediaType(TEXT_PLAIN_TYPE).withFilename("item1.txt").build();
    OutputItem item2 = anOutputItem().withName("item2").withEntity("{\"item2\":\"entity\"}").withMediaType(APPLICATION_JSON_TYPE).withFilename("item2.json").build();
    Collection<OutputItem> items = newArrayList(item1, item2);
    Class<Collection> type = Collection.class;
    ParameterizedType genericType = ParameterizedTypeImpl.newParameterizedType(Collection.class, OutputItem.class);
    Annotation[] annotations = new Annotation[0];
    MediaType mediaType = new MediaType("multipart", "form-data", ImmutableMap.of("boundary", "1234567"));
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
    OutputStream out = new ByteArrayOutputStream();
    collectionMultipartFormDataMessageBodyWriter.writeTo(items, type, genericType, annotations, mediaType, headers, out);
    verify(multipartFormDataWriter).writeItems(same(items), same(out), aryEq("1234567".getBytes()));
    MediaType mediaTypeWithBoundary = (MediaType)headers.getFirst("Content-type");
    assertNotNull(mediaTypeWithBoundary);
    String boundary = mediaTypeWithBoundary.getParameters().get("boundary");
    assertEquals("1234567", boundary);
}