01: /*
02: * Copyright (C) 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 12. September 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.acceptance;
12:
13: import com.thoughtworks.xstream.XStream;
14: import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
15: import com.thoughtworks.xstream.io.xml.XppDriver;
16:
17: public class XmlFriendlyDollarOnlyTest extends XmlFriendlyTest {
18:
19: protected XStream createXStream() {
20: return new XStream(new XppDriver(new XmlFriendlyReplacer("_-",
21: "_")));
22: }
23:
24: protected Object assertBothWays(Object root, String xml) {
25: return super .assertBothWays(root, replaceAll(xml, "__", "_"));
26: }
27:
28: // String.replaceAll is JDK 1.4
29: protected String replaceAll(String s, final String occurance,
30: final String replacement) {
31: final int len = occurance.length();
32: final int inc = len - replacement.length();
33: int i = -inc;
34: final StringBuffer buff = new StringBuffer(s);
35: // StringBuffer has no indexOf in JDK 1.3
36: while ((i = buff.toString().indexOf(occurance, i + inc)) >= 0) {
37: buff.replace(i, i + len, replacement);
38: }
39: return buff.toString();
40: }
41:
42: }
|