public static void appendSingleAttachmentToBuilder(final MultiPartMIMEWriter.Builder builder,
                                                     final RestLiAttachmentDataSourceWriter streamingAttachment)
  {
    builder.appendDataSource(new MultiPartMIMEDataSourceWriter()
    {
      @Override
      public Map<String, String> dataSourceHeaders()
      {
        final Map<String, String> dataSourceHeaders = new TreeMap<>();
        dataSourceHeaders.put(RestConstants.HEADER_CONTENT_ID, streamingAttachment.getAttachmentID());
        return dataSourceHeaders;
      }

      @Override
      public void onInit(WriteHandle wh)
      {
        streamingAttachment.onInit(wh);
      }

      @Override
      public void onWritePossible()
      {
        streamingAttachment.onWritePossible();
      }

      @Override
      public void onAbort(Throwable e)
      {
        streamingAttachment.onAbort(e);
      }
    });
  }
@Test
  public void testSingleAttachment()
  {
    final MultiPartMIMEWriter.Builder builder = new MultiPartMIMEWriter.Builder();
    final List<RestLiTestAttachmentDataSource> testAttachmentDataSources = generateTestDataSources();

    for (RestLiTestAttachmentDataSource dataSource : testAttachmentDataSources)
    {
      AttachmentUtils.appendSingleAttachmentToBuilder(builder, dataSource);
    }

    final StreamRequest streamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(
        URI.create("foo"), "related", builder.build());

    final MultiPartMIMEReader streamRequestReader = MultiPartMIMEReader.createAndAcquireStream(streamRequest);
    final CountDownLatch streamRequestReaderLatch = new CountDownLatch(1);
    final MIMETestUtils.MultiPartMIMEFullReaderCallback
        streamRequestReaderCallback = new MIMETestUtils.MultiPartMIMEFullReaderCallback(streamRequestReaderLatch);
    streamRequestReader.registerReaderCallback(streamRequestReaderCallback);
    try
    {
      streamRequestReaderLatch.await(3000, TimeUnit.MILLISECONDS);
    }
    catch (InterruptedException interruptedException)
    {
      Assert.fail();
    }
    verifyAttachments(streamRequestReaderCallback.getSinglePartMIMEReaderCallbacks(), testAttachmentDataSources);
  }