1 16 17 package org.springframework.web.servlet.view.xslt; 18 19 import java.util.Locale ; 20 import java.util.TimeZone ; 21 22 import junit.framework.TestCase; 23 import org.w3c.dom.Element ; 24 25 32 public class FormatHelperTests extends TestCase { 33 34 private static final long testTime = 1064359582063L; 36 39 public void testNullParamsForLocale() { 40 try { 41 Element e = (Element ) FormatHelper.dateTimeElement(testTime, null, null); 42 e = (Element ) FormatHelper.dateTimeElement(testTime, "", null); 43 e = (Element ) FormatHelper.dateTimeElement(testTime, null, ""); 44 } 45 catch (Throwable ex) { 46 fail( "Passing null params to dateTimeElement(long, String, String) throws " + ex.getClass().getName()); 47 } 48 49 try { 50 String s = FormatHelper.currency(50d, null, null); 51 s = FormatHelper.currency(50d, "", null); 52 s = FormatHelper.currency(50d, null, ""); 53 } 54 catch (Throwable ex) { 55 fail( "Passing null params to currency(long, String, String) throws " + ex.getClass().getName()); 56 } 57 } 58 59 public void testDateTimeElement() { 60 TimeZone curr = TimeZone.getDefault(); 62 TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); 64 65 Element e = (Element ) FormatHelper.dateTimeElement(testTime, Locale.UK); 66 assertTrue(e.getTagName().equals("formatted-date")); 67 Element el = (Element ) e.getElementsByTagName("year").item(0); 68 assertTrue("2003".equals(el.getFirstChild().getNodeValue())); 69 el = (Element ) e.getElementsByTagName("month").item(0); 70 assertTrue("September".equals(el.getFirstChild().getNodeValue())); 71 el = (Element ) e.getElementsByTagName("day-of-week").item(0); 72 assertTrue("Wednesday".equals(el.getFirstChild().getNodeValue())); 73 el = (Element ) e.getElementsByTagName("day-of-month").item(0); 74 assertTrue("24".equals(el.getFirstChild().getNodeValue())); 75 el = (Element ) e.getElementsByTagName("hours").item(0); 76 assertEquals( "12", el.getFirstChild().getNodeValue() ); 77 el = (Element ) e.getElementsByTagName("minutes").item(0); 78 assertTrue("26".equals(el.getFirstChild().getNodeValue())); 79 el = (Element ) e.getElementsByTagName("am-pm").item(0); 80 assertTrue("AM".equals(el.getFirstChild().getNodeValue())); 81 82 e = (Element ) FormatHelper.dateTimeElement(testTime, Locale.FRANCE); 84 el = (Element ) e.getElementsByTagName("day-of-week").item(0); 85 assertTrue("mercredi".equals(el.getFirstChild().getNodeValue())); 86 87 TimeZone.setDefault(curr); 89 } 90 91 public void testCurrency() { 92 String s = FormatHelper.currency( 50.0d, Locale.US); 93 assertTrue( "$50.00".equals(s)); 94 95 s = FormatHelper.currency( 50.0d, Locale.UK); 97 assertEquals( 163, s.charAt(0)); 98 assertTrue( "50.00".equals(s.substring(1))); 99 100 s = FormatHelper.currency( 50.0d, Locale.FRANCE); 102 assertTrue( "50,00".equals(s.substring(0,5))); 103 104 } 105 106 } 107 | Popular Tags |