1 package com.thoughtworks.acceptance; 2 3 import com.thoughtworks.xstream.XStream; 4 import com.thoughtworks.xstream.io.xml.XppDriver; 5 import junit.framework.TestCase; 6 7 import java.lang.reflect.Array ; 8 9 public abstract class AbstractAcceptanceTest extends TestCase { 10 11 protected XStream xstream = new XStream(new XppDriver()); 12 13 protected Object assertBothWays(Object root, String xml) { 14 String resultXml = xstream.toXML(root); 15 assertEquals(xml, resultXml); 16 Object resultRoot = xstream.fromXML(resultXml); 17 compareObjects(root, resultRoot); 18 return resultRoot; 19 } 20 21 protected void compareObjects(Object expected, Object actual) { 22 if (expected == null) { 23 assertNull(actual); 24 } else { 25 assertNotNull(actual); 26 if (actual.getClass().isArray()) { 27 assertArrayEquals(expected, actual); 28 } else { 29 assertEquals(expected.getClass(), actual.getClass()); 30 assertEquals(expected, actual); 31 } 32 } 33 } 34 35 protected void assertArrayEquals(Object expected, Object actual) { 36 assertEquals(Array.getLength(expected), Array.getLength(actual)); 37 for (int i = 0; i < Array.getLength(expected); i++) { 38 assertEquals(Array.get(expected, i), Array.get(actual, i)); 39 } 40 } 41 } 42 | Popular Tags |