KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > converters > reflection > Sun14ReflectionProviderTest


1 package com.thoughtworks.xstream.converters.reflection;
2
3 public class Sun14ReflectionProviderTest extends AbstractReflectionProviderTest {
4
5     // inherits tests from superclass
6

7     public ReflectionProvider createReflectionProvider() {
8         return new Sun14ReflectionProvider();
9     }
10
11     public void testCanWriteFinalFields() {
12         WithFinalFields thingy = new WithFinalFields();
13         reflectionProvider.writeField(thingy, "finalField", "zero", WithFinalFields.class);
14         assertEquals("zero", thingy.finalField);
15
16         reflectionProvider.writeField(thingy, "finalInt", new Integer JavaDoc(1), WithFinalFields.class);
17         assertEquals(1, thingy.finalInt);
18
19         reflectionProvider.writeField(thingy, "finalLong", new Long JavaDoc(2), WithFinalFields.class);
20         assertEquals(2, thingy.finalLong);
21
22         reflectionProvider.writeField(thingy, "finalShort", new Short JavaDoc((short) 3), WithFinalFields.class);
23         assertEquals(3, thingy.finalShort);
24
25         reflectionProvider.writeField(thingy, "finalChar", new Character JavaDoc('4'), WithFinalFields.class);
26         assertEquals('4', thingy.finalChar);
27
28         reflectionProvider.writeField(thingy, "finalByte", new Byte JavaDoc((byte) 5), WithFinalFields.class);
29         assertEquals(5, thingy.finalByte);
30
31         reflectionProvider.writeField(thingy, "finalFloat", new Float JavaDoc(0.6), WithFinalFields.class);
32         assertEquals(0.6f, thingy.finalFloat, 0.0);
33
34         reflectionProvider.writeField(thingy, "finalDouble", new Double JavaDoc(0.7), WithFinalFields.class);
35         assertEquals(0.7, thingy.finalDouble, 0.0);
36
37         reflectionProvider.writeField(thingy, "finalBoolean", new Boolean JavaDoc(true), WithFinalFields.class);
38         assertEquals(true, thingy.finalBoolean);
39
40         reflectionProvider.writeField(thingy, "finalBoolean", new Boolean JavaDoc(false), null);
41         assertEquals(false, thingy.finalBoolean);
42     }
43
44     private static class WithFinalFields {
45         final String JavaDoc finalField;
46         final int finalInt;
47         final long finalLong;
48         final short finalShort;
49         final char finalChar;
50         final byte finalByte;
51         final float finalFloat;
52         final double finalDouble;
53         final boolean finalBoolean;
54
55         private WithFinalFields() {
56             finalField = null;
57             finalChar = '\0';
58             finalInt = 0;
59             finalLong = 0;
60             finalShort = 0;
61             finalByte = 0;
62             finalFloat = 0.0f;
63             finalDouble = 0.0;
64             finalBoolean = false;
65         }
66
67     }
68
69 }
Popular Tags