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