@Test
public void writesJAXBElementToOutputStream() throws Exception {

    Class<?> type = JAXBElement.class;
    Type genericType = newParameterizedType(JAXBElement.class, Book.class);
    JAXBElement<Book> bookJAXBElement = unmarshalJAXBElement(TEST_XML_CONTENT_BYTES);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.writeTo(bookJAXBElement, type, genericType, null, APPLICATION_XML_TYPE, null, out);
    JAXBElement<Book> writtenBookJAXBElement = unmarshalJAXBElement(out.toByteArray());
    Book book = writtenBookJAXBElement.getValue();
    assertEquals("Java and XML Data Binding", book.getTitle());
    assertTrue(book.isSendByPost());
    assertEquals("Brett McLaughlin", book.getAuthor());
    assertEquals("USD", book.getPrice().getCurrency());
    assertEquals(new BigDecimal("34.95"), book.getPrice().getValue());
    assertEquals("USD", book.getMemberPrice().getCurrency());
    assertEquals(new BigDecimal("26.56"), book.getMemberPrice().getValue());
}