From 9a05c7404cd4bbb41d84b15eaa157068f08590eb Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 21 May 2003 23:41:21 +0000 Subject: [PATCH] Update testing for FastDateFormat git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137328 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang/time/FastDateFormatTest.java | 115 ++++++++++-------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/src/test/org/apache/commons/lang/time/FastDateFormatTest.java b/src/test/org/apache/commons/lang/time/FastDateFormatTest.java index 6533c7c5e..749efe43f 100644 --- a/src/test/org/apache/commons/lang/time/FastDateFormatTest.java +++ b/src/test/org/apache/commons/lang/time/FastDateFormatTest.java @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,20 +51,23 @@ * information on the Apache Software Foundation, please see * . */ - package org.apache.commons.lang.time; -import junit.framework.*; +import java.text.SimpleDateFormat; +import java.util.Locale; +import java.util.TimeZone; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; import junit.textui.TestRunner; -import java.util.*; -import java.text.*; /** * Unit tests {@link org.apache.commons.lang.time.FastDateFormat}. * * @author Sean Schofield * @since 2.0 - * @version $Id: FastDateFormatTest.java,v 1.2 2003/01/07 21:21:43 bayard Exp $ + * @version $Id: FastDateFormatTest.java,v 1.3 2003/05/21 23:41:21 scolebourne Exp $ */ public class FastDateFormatTest extends TestCase { @@ -97,6 +100,7 @@ public void test_getInstance() { FastDateFormat format1 = FastDateFormat.getInstance(); FastDateFormat format2 = FastDateFormat.getInstance(); assertSame(format1, format2); + assertEquals(new SimpleDateFormat().toPattern(), format1.getPattern()); } public void test_getInstance_String() { @@ -104,64 +108,75 @@ public void test_getInstance_String() { FastDateFormat format2 = FastDateFormat.getInstance("MM-DD-yyyy"); assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); assertSame(format1, FastDateFormat.getInstance("MM/DD/yyyy")); + assertEquals("MM/DD/yyyy", format1.getPattern()); } public void test_getInstance_String_TimeZone() { Locale realDefaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); TimeZone realDefaultZone = TimeZone.getDefault(); - TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); - - FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", - TimeZone.getTimeZone("Atlantic/Reykjavik")); - FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); - FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); - FastDateFormat format4 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); - FastDateFormat format5 = FastDateFormat.getInstance("MM-DD-yyyy", TimeZone.getDefault()); - - assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); - assertTrue(format1.getTimeZone().equals(TimeZone.getTimeZone("Atlantic/Reykjavik"))); - assertNull(format2.getTimeZone()); - assertSame(format3, format4); - assertTrue(format3 != format5); // -- junit 3.8 version -- assertFalse(format3 == format5); - - Locale.setDefault(realDefaultLocale); - TimeZone.setDefault(realDefaultZone); + try { + Locale.setDefault(Locale.US); + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); + + FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", + TimeZone.getTimeZone("Atlantic/Reykjavik")); + FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); + FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); + FastDateFormat format4 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); + FastDateFormat format5 = FastDateFormat.getInstance("MM-DD-yyyy", TimeZone.getDefault()); + + assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); + assertTrue(format1.getTimeZone().equals(TimeZone.getTimeZone("Atlantic/Reykjavik"))); + assertNull(format2.getTimeZone()); + assertSame(format3, format4); + assertTrue(format3 != format5); // -- junit 3.8 version -- assertFalse(format3 == format5); + + } finally { + Locale.setDefault(realDefaultLocale); + TimeZone.setDefault(realDefaultZone); + } } public void test_getInstance_String_Locale() { Locale realDefaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); - FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); - FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); - FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); + try { + Locale.setDefault(Locale.US); + FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); + FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); + FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); - assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); - assertSame(format1, format3); - assertSame(Locale.GERMANY, format1.getLocale()); - - Locale.setDefault(realDefaultLocale); + assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); + assertSame(format1, format3); + assertSame(Locale.GERMANY, format1.getLocale()); + + } finally { + Locale.setDefault(realDefaultLocale); + } } public void test_getInstance_String_TimeZone_Locale() { Locale realDefaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.US); TimeZone realDefaultZone = TimeZone.getDefault(); - TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); - - FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", - TimeZone.getTimeZone("Atlantic/Reykjavik"), Locale.GERMANY); - FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); - FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", - TimeZone.getDefault(), Locale.GERMANY); - - assertTrue(format1 != format2); // -- junit 3.8 version -- assertNotSame(format1, format2); - assertEquals(format1.getTimeZone(), TimeZone.getTimeZone("Atlantic/Reykjavik")); - assertNull(format2.getTimeZone()); - assertEquals(format3.getTimeZone(), TimeZone.getDefault()); - assertEquals(format3.getTimeZone(), TimeZone.getTimeZone("America/New_York")); - - Locale.setDefault(realDefaultLocale); - TimeZone.setDefault(realDefaultZone); + try { + Locale.setDefault(Locale.US); + TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); + + FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", + TimeZone.getTimeZone("Atlantic/Reykjavik"), Locale.GERMANY); + FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); + FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", + TimeZone.getDefault(), Locale.GERMANY); + + assertTrue(format1 != format2); // -- junit 3.8 version -- assertNotSame(format1, format2); + assertEquals(format1.getTimeZone(), TimeZone.getTimeZone("Atlantic/Reykjavik")); + assertNull(format2.getTimeZone()); + assertEquals(format3.getTimeZone(), TimeZone.getDefault()); + assertEquals(format3.getTimeZone(), TimeZone.getTimeZone("America/New_York")); + + } finally { + Locale.setDefault(realDefaultLocale); + TimeZone.setDefault(realDefaultZone); + } } + }