JAXBService { public String marshall(Object object) { StringWriter sw = new StringWriter(); try { sw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); marshaller.marshal(object, sw); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } return sw.toString(); } JAXBService(Class<?>... xsdRootClasses); static JAXBService create(Class<?>... xsdClasses); static JAXBService createWithValidation(Class<?>... xsdClasses); void validateWithLocalCacheXSD(); String marshall(Object object); T unMarshall(String xml); T unMarshall(String xml, Class<T> klass);  }
@Test public void invalidXmlShouldFail() { CacheConfig cacheConfig = new CacheConfig(); assertThatThrownBy(() -> service.marshall(cacheConfig)) .hasStackTraceContaining("Attribute 'version' must appear on element 'cache'"); }
@Test public void testCacheOneMarshall() { CacheConfig cache = new CacheConfig(); setBasicValues(cache); cache.getCustomCacheElements().add(new ElementOne("test")); xml = service.marshall(cache); System.out.println(xml); assertThat(xml).contains("xmlns=\"http: assertThat(xml).contains("custom-one>"); }