KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thoughtworks.acceptance;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.math.BigInteger JavaDoc;
5 import java.util.Date JavaDoc;
6
7 public class BasicTypesTest extends AbstractAcceptanceTest {
8
9     public void testPrimitiveNumbers() {
10         assertBothWays(new Integer JavaDoc(99), "<int>99</int>");
11         assertBothWays(new Integer JavaDoc(-99), "<int>-99</int>");
12         assertBothWays(new Integer JavaDoc(0), "<int>0</int>");
13         assertBothWays(new Float JavaDoc(-123.45f), "<float>-123.45</float>");
14         assertBothWays(new Double JavaDoc(-1234567890.12345), "<double>-1.23456789012345E9</double>");
15         assertBothWays(new Long JavaDoc(123456789123456L), "<long>123456789123456</long>");
16         assertBothWays(new Short JavaDoc((short) 123), "<short>123</short>");
17     }
18
19     public void testDifferentBaseIntegers() {
20         assertEquals(new Integer JavaDoc(255), xstream.fromXML("<int>0xFF</int>"));
21         assertEquals(new Integer JavaDoc(8), xstream.fromXML("<int>010</int>"));
22     }
23
24     public void testOtherPrimitives() {
25         assertBothWays(new Character JavaDoc('z'), "<char>z</char>");
26         assertBothWays(Boolean.TRUE, "<boolean>true</boolean>");
27         assertBothWays(Boolean.FALSE, "<boolean>false</boolean>");
28         assertBothWays(new Byte JavaDoc((byte) 44), "<byte>44</byte>");
29     }
30
31     public void testStrings() {
32         assertBothWays("hello world", "<string>hello world</string>");
33     }
34
35     public void testStringBuffer() {
36         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
37         buffer.append("woo");
38         String JavaDoc xml = xstream.toXML(buffer);
39         assertEquals(xml, "<string-buffer>woo</string-buffer>");
40         StringBuffer JavaDoc out = (StringBuffer JavaDoc) xstream.fromXML(xml);
41         assertEquals("woo", out.toString());
42     }
43
44     public void testDate() {
45         Date JavaDoc date = new Date JavaDoc(103, 02, 15, 8, 22, 7);
46         assertBothWays(date, "<date>2003-03-15 08:22:07.0 AM</date>");
47     }
48
49     public void testBigInteger() {
50         BigInteger JavaDoc bigInteger = new BigInteger JavaDoc("1234567890123456");
51         assertBothWays(bigInteger, "<big-int>1234567890123456</big-int>");
52     }
53
54     public void testBigDecimal() {
55         BigDecimal JavaDoc bigDecimal = new BigDecimal JavaDoc("1234567890123456.987654321");
56         assertBothWays(bigDecimal, "<big-decimal>1234567890123456.987654321</big-decimal>");
57     }
58
59 }
60
Popular Tags