01: /*
02: * Copyright (C) 2004 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 08. March 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.reflection;
13:
14: public class Sun14ReflectionProviderTest extends
15: AbstractReflectionProviderTest {
16:
17: // inherits tests from superclass
18:
19: public ReflectionProvider createReflectionProvider() {
20: return new Sun14ReflectionProvider();
21: }
22:
23: public void testCanWriteFinalFields() {
24: WithFinalFields thingy = new WithFinalFields();
25: reflectionProvider.writeField(thingy, "finalField", "zero",
26: WithFinalFields.class);
27: assertEquals("zero", thingy.finalField);
28:
29: reflectionProvider.writeField(thingy, "finalInt",
30: new Integer(1), WithFinalFields.class);
31: assertEquals(1, thingy.finalInt);
32:
33: reflectionProvider.writeField(thingy, "finalLong", new Long(2),
34: WithFinalFields.class);
35: assertEquals(2, thingy.finalLong);
36:
37: reflectionProvider.writeField(thingy, "finalShort", new Short(
38: (short) 3), WithFinalFields.class);
39: assertEquals(3, thingy.finalShort);
40:
41: reflectionProvider.writeField(thingy, "finalChar",
42: new Character('4'), WithFinalFields.class);
43: assertEquals('4', thingy.finalChar);
44:
45: reflectionProvider.writeField(thingy, "finalByte", new Byte(
46: (byte) 5), WithFinalFields.class);
47: assertEquals(5, thingy.finalByte);
48:
49: reflectionProvider.writeField(thingy, "finalFloat", new Float(
50: 0.6), WithFinalFields.class);
51: assertEquals(0.6f, thingy.finalFloat, 0.0);
52:
53: reflectionProvider.writeField(thingy, "finalDouble",
54: new Double(0.7), WithFinalFields.class);
55: assertEquals(0.7, thingy.finalDouble, 0.0);
56:
57: reflectionProvider.writeField(thingy, "finalBoolean",
58: new Boolean(true), WithFinalFields.class);
59: assertEquals(true, thingy.finalBoolean);
60:
61: reflectionProvider.writeField(thingy, "finalBoolean",
62: new Boolean(false), null);
63: assertEquals(false, thingy.finalBoolean);
64: }
65:
66: private static class WithFinalFields {
67: final String finalField;
68: final int finalInt;
69: final long finalLong;
70: final short finalShort;
71: final char finalChar;
72: final byte finalByte;
73: final float finalFloat;
74: final double finalDouble;
75: final boolean finalBoolean;
76:
77: private WithFinalFields() {
78: finalField = null;
79: finalChar = '\0';
80: finalInt = 0;
81: finalLong = 0;
82: finalShort = 0;
83: finalByte = 0;
84: finalFloat = 0.0f;
85: finalDouble = 0.0;
86: finalBoolean = false;
87: }
88:
89: }
90:
91: }
|