CrescentCollectionHandler { public void writeToXML() { ResourceLoader resourceLoader = new ResourceLoader(collectionsXmlLocation); URL collectionXmlUrl = resourceLoader.getURL(); XStream stream = new XStream(); stream.processAnnotations(CrescentCollections.class); logger.debug("collectionXmlUrl : {}", collectionXmlUrl); try { File collectionsXmlFile = new File(collectionXmlUrl.toURI()); logger.debug("collectionXmlUrl to URI: {}", collectionXmlUrl.toURI()); logger.debug("collectionsXmlFile : {}", collectionsXmlFile); FileOutputStream fos = new FileOutputStream(collectionsXmlFile, false); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, Charset.forName("utf-8"))); stream.toXML(this.crescentCollections, bw); bw.close(); fos.close(); } catch (URISyntaxException e) { e.printStackTrace(); logger.error("error : ", e); } catch (FileNotFoundException e) { e.printStackTrace(); logger.error("error : ", e); } catch (IOException e) { e.printStackTrace(); logger.error("error : ", e); } }  CrescentCollections getCrescentCollections(); void writeToXML(); void reloadCollectionsXML();  }
@Test public void writeToXML() { CrescentCollectionHandler collectionHandler = SpringApplicationContext.getBean("crescentCollectionHandler", CrescentCollectionHandler.class); CrescentCollections collections = collectionHandler.getCrescentCollections(); System.out.println(collections); Assert.assertNotNull(collections); collectionHandler.writeToXML(); collectionHandler.reloadCollectionsXML(); CrescentCollections collections2 = collectionHandler.getCrescentCollections(); System.out.println(collections2); }