KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > acceptance > AwkwardCharactersTest


1 package com.thoughtworks.acceptance;
2
3 public class AwkwardCharactersTest extends AbstractAcceptanceTest {
4
5     public static class WithDollarCharField extends StandardObject {
6         String JavaDoc $field;
7         String JavaDoc field$;
8         String JavaDoc fi$eld;
9         String JavaDoc fi$$eld;
10     }
11
12     public void testSupportsFieldsWithDollarChar() {
13         xstream.alias("dollar", WithDollarCharField.class);
14
15         WithDollarCharField in = new WithDollarCharField();
16         in.$field = "a";
17         in.field$ = "b";
18         in.fi$eld = "c";
19         in.fi$$eld = "d";
20
21         String JavaDoc expected = "" +
22                 "<dollar>\n" +
23                 " <_DOLLAR_field>a</_DOLLAR_field>\n" +
24                 " <field_DOLLAR_>b</field_DOLLAR_>\n" +
25                 " <fi_DOLLAR_eld>c</fi_DOLLAR_eld>\n" +
26                 " <fi_DOLLAR__DOLLAR_eld>d</fi_DOLLAR__DOLLAR_eld>\n" +
27                 "</dollar>";
28         assertBothWays(in, expected);
29     }
30
31     public static class WithUnderscoreCharField extends StandardObject {
32         String JavaDoc _field;
33         String JavaDoc field_;
34         String JavaDoc fi_eld;
35         String JavaDoc fi__eld;
36     }
37
38     public void testSupportsFieldsWithUnderscoreChar() {
39         xstream.alias("underscore", WithUnderscoreCharField.class);
40
41         WithUnderscoreCharField in = new WithUnderscoreCharField();
42         in._field = "a";
43         in.field_ = "b";
44         in.fi_eld = "c";
45         in.fi__eld = "d";
46
47         String JavaDoc expected = "" +
48                 "<underscore>\n" +
49                 " <__field>a</__field>\n" +
50                 " <field__>b</field__>\n" +
51                 " <fi__eld>c</fi__eld>\n" +
52                 " <fi____eld>d</fi____eld>\n" +
53                 "</underscore>";
54         assertBothWays(in, expected);
55     }
56
57     public static class A_B extends StandardObject {
58         private int x;
59
60         public A_B(int x) {
61             this.x = x;
62         }
63
64     }
65
66     public void testSupportsUnderscoreInShortClassName() {
67         assertBothWays(new A_B(3), ""
68                 + "<com.thoughtworks.acceptance.AwkwardCharactersTest-A_B>\n"
69                 + " <x>3</x>\n"
70                 + "</com.thoughtworks.acceptance.AwkwardCharactersTest-A_B>");
71     }
72
73     public void testSlashRSlashSlashSlashN() {
74         String JavaDoc before = "\r\\\n";
75         String JavaDoc xml = xstream.toXML(before);
76         assertEquals(before, xstream.fromXML(xml));
77     }
78
79 }
80
Popular Tags