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 23. November 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.acceptance.annotations;
12:
13: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14: import com.thoughtworks.xstream.XStream;
15: import com.thoughtworks.xstream.annotations.XStreamAlias;
16: import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
17:
18: /**
19: * Tests annotations defining fields to be rendered as attributes.
20: *
21: * @author Chung-Onn Cheong
22: * @author Mauro Talevi
23: * @author Guilherme Silveira
24: * @author Jörg Schaible
25: */
26: public class AttributesTest extends AbstractAcceptanceTest {
27:
28: @Override
29: protected XStream createXStream() {
30: XStream xstream = super .createXStream();
31: xstream.autodetectAnnotations(true);
32: return xstream;
33: }
34:
35: @XStreamAlias("annotated")
36: public static class AnnotatedAttribute {
37: @XStreamAsAttribute
38: private String myField;
39: }
40:
41: public void testAnnotation() {
42: AnnotatedAttribute value = new AnnotatedAttribute();
43: value.myField = "hello";
44: String expected = "<annotated myField=\"hello\"/>";
45: assertBothWays(value, expected);
46: }
47:
48: @XStreamAlias("annotated")
49: public static class AnnotatedAliasedAttribute {
50: @XStreamAsAttribute
51: @XStreamAlias("field")
52: private String myField;
53: }
54:
55: public void testAnnotationInCombinationWithAlias() {
56: AnnotatedAliasedAttribute value = new AnnotatedAliasedAttribute();
57: value.myField = "hello";
58: String expected = "<annotated field=\"hello\"/>";
59: assertBothWays(value, expected);
60: }
61: }
|