1 package com.thoughtworks.xstream.converters.collections; 2 3 import com.thoughtworks.acceptance.AbstractAcceptanceTest; 4 5 public class ByteArrayConverterTest extends AbstractAcceptanceTest { 6 7 8 public void testMarshallByteArrays() { 9 Dummy input = new Dummy(new byte[0]); 10 11 String expected = "<dummy>\n <data></data>\n</dummy>"; 12 assertBothWays(input, expected); 13 } 14 15 public static class Dummy { 16 byte[] data; 17 18 public Dummy(byte[] data) { 19 this.data = data; 20 } 21 22 public byte[] getData() { 23 return data; 24 } 25 26 public boolean equals(Object that) { 27 if (that instanceof Dummy) { 28 return equals((Dummy) that); 29 } 30 return false; 31 } 32 33 public boolean equals(Dummy that) { 34 if (this.data == that.data) { 35 return true; 36 } 37 if (this.data != null && that.data != null) { 38 if (this.data.length == that.data.length) { 39 for (int i = 0; i < data.length; i++) { 40 byte b1 = data[i]; 41 byte b2 = that.data[i]; 42 if (b1 != b2) { 43 return false; 44 } 45 } 46 return true; 47 } 48 } 49 return false; 50 51 } 52 } 53 54 protected void setUp() throws Exception { 55 super.setUp(); 56 xstream.alias("dummy", Dummy.class); 57 } 58 } 59 | Popular Tags |