1 4 package org.oddjob.values.types; 5 6 import java.text.ParseException ; 7 import java.util.Date ; 8 import java.util.TimeZone ; 9 10 import junit.framework.TestCase; 11 12 import org.apache.log4j.Logger; 13 import org.oddjob.util.DateHelper; 14 15 18 public class FormatTypeTest extends TestCase { 19 private static final Logger logger = Logger.getLogger(FormatTypeTest.class); 20 21 public void testLocalDate() throws ParseException { 22 TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); 23 24 Date date = DateHelper.parseDateTime("1-nov-05 22:00"); 25 26 FormatType ft = new FormatType(); 27 ft.setDate(date); 28 ft.setFormat("yyyyMMdd"); 29 30 String result = ft.valueFor(Object .class); 31 32 assertEquals("20051101", result); 33 } 34 35 public void testTimeZoneDate() throws ParseException { 36 TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); 37 38 Date date = DateHelper.parseDateTime("1-nov-05 22:00", "America/Chicago"); 39 logger.debug(date); 40 FormatType ft = new FormatType(); 41 ft.setDate(date); 42 ft.setFormat("yyyyMMdd"); 43 ft.setTimeZone("America/Chicago"); 44 45 String result = ft.valueFor(Object .class); 46 47 assertEquals("20051101", result); 48 } 49 50 public void testNumberFormat() throws ParseException { 51 52 FormatType ft = new FormatType(); 53 ft.setNumber(new Integer (22)); 54 ft.setFormat("##0.00"); 55 56 String result = ft.valueFor(Object .class); 57 58 assertEquals("22.00", result); 59 } 60 } 61 | Popular Tags |