ProductTypeRangeListXStreamProvider implements XStreamProvider<RangeList> { private XStream provide() { if (this.xStream == null) { XStream xStream = new XStream(new DomDriver()); xStream.addPermission(AnyTypePermission.ANY); xStream.addDefaultImplementation(ArrayList.class, List.class); xStream.addDefaultImplementation(RangeNodeImpl.class, RangeNode.class); xStream.addDefaultImplementation(DisplayValueImpl.class, DisplayValue.class); xStream.alias("range-list", RangeListImpl.class); xStream.alias("range", RangeNode.class); xStream.alias("display", DisplayValue.class); this.xStream = xStream; } return this.xStream; }  @Override RangeList fromXML(final String xml); @Override RangeList fromXML(final InputStream is); @Override String toXML(final RangeList object);  }
@Test public void testProvide() throws Exception { final XStreamProvider<RangeList> provider = new ProductTypeRangeListXStreamProvider(); final String xml = new Scanner(new File("src/test/resources/weight_filtering_example.xml")).useDelimiter("\\Z").next(); final RangeList rl = provider.fromXML(xml); assertNotNull(rl); assertEquals(4, rl.getRanges().size()); assertEquals("0.10", (rl.getRanges().get(0)).getFrom()); assertEquals("1.00", (rl.getRanges().get(0)).getTo()); final List<DisplayValue> i18n = (rl.getRanges().get(0)).getI18n(); assertNotNull(i18n); assertEquals(2, i18n.size()); assertEquals("en", i18n.get(0).getLang()); assertEquals("100 g - 1 kg", i18n.get(0).getValue()); assertEquals("ru", i18n.get(1).getLang()); assertEquals("100 g - 1 kg ru", i18n.get(1).getValue()); final String xmlStr = provider.toXML(rl); assertNotNull(xmlStr); final RangeList rl2 = provider.fromXML(xmlStr); assertNotNull(rl2); assertEquals(4, rl2.getRanges().size()); assertEquals("0.10", (rl2.getRanges().get(0)).getFrom()); assertEquals("1.00", (rl2.getRanges().get(0)).getTo()); }