JAXBContextFactory { public Marshaller createMarshaller(Class<?> clazz) throws JAXBException { Marshaller marshaller = getContext(clazz).createMarshaller(); setMarshallerProperties(marshaller); return marshaller; } private  JAXBContextFactory(Map<String, Object> properties); Unmarshaller createUnmarshaller(Class<?> clazz); Marshaller createMarshaller(Class<?> clazz);  }
@Test public void buildsMarshallerWithJAXBEncodingProperty() throws Exception { JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerJAXBEncoding("UTF-16").build(); Marshaller marshaller = factory.createMarshaller(Object.class); assertEquals("UTF-16", marshaller.getProperty(Marshaller.JAXB_ENCODING)); }
@Test public void buildsMarshallerWithSchemaLocationProperty() throws Exception { JAXBContextFactory factory = new JAXBContextFactory.Builder() .withMarshallerSchemaLocation("http: .build(); Marshaller marshaller = factory.createMarshaller(Object.class); assertEquals("http: marshaller.getProperty(Marshaller.JAXB_SCHEMA_LOCATION)); }
@Test public void buildsMarshallerWithNoNamespaceSchemaLocationProperty() throws Exception { JAXBContextFactory factory = new JAXBContextFactory.Builder() .withMarshallerNoNamespaceSchemaLocation("http: Marshaller marshaller = factory.createMarshaller(Object.class); assertEquals("http: marshaller.getProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION)); }
@Test public void buildsMarshallerWithFormattedOutputProperty() throws Exception { JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerFormattedOutput(true).build(); Marshaller marshaller = factory.createMarshaller(Object.class); assertTrue((Boolean) marshaller.getProperty(Marshaller.JAXB_FORMATTED_OUTPUT)); }
@Test public void buildsMarshallerWithFragmentProperty() throws Exception { JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerFragment(true).build(); Marshaller marshaller = factory.createMarshaller(Object.class); assertTrue((Boolean) marshaller.getProperty(Marshaller.JAXB_FRAGMENT)); }