01: /*
02: * Copyright (C) 2004, 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 25. April 2004 by James Strachan
11: */
12: package com.thoughtworks.xstream.converters.collections;
13:
14: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
15:
16: public class ByteArrayConverterTest extends AbstractAcceptanceTest {
17:
18: public void testMarshallByteArrays() {
19: Dummy input = new Dummy(new byte[0]);
20:
21: String expected = "<dummy>\n <data></data>\n</dummy>";
22: assertBothWays(input, expected);
23: }
24:
25: public static class Dummy {
26: byte[] data;
27:
28: private Dummy() {
29: }
30:
31: public Dummy(byte[] data) {
32: this .data = data;
33: }
34:
35: public byte[] getData() {
36: return data;
37: }
38:
39: public boolean equals(Object that) {
40: if (that instanceof Dummy) {
41: return equals((Dummy) that);
42: }
43: return false;
44: }
45:
46: public boolean equals(Dummy that) {
47: if (this .data == that.data) {
48: return true;
49: }
50: if (this .data != null && that.data != null) {
51: if (this .data.length == that.data.length) {
52: for (int i = 0; i < data.length; i++) {
53: byte b1 = data[i];
54: byte b2 = that.data[i];
55: if (b1 != b2) {
56: return false;
57: }
58: }
59: return true;
60: }
61: }
62: return false;
63:
64: }
65: }
66:
67: protected void setUp() throws Exception {
68: super .setUp();
69: xstream.alias("dummy", Dummy.class);
70: }
71: }
|