Update testing for FastDateFormat

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137328 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-05-21 23:41:21 +00:00
parent a4452d34e1
commit 9a05c7404c

View File

@ -1,7 +1,7 @@
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -51,20 +51,23 @@
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.commons.lang.time; 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 junit.textui.TestRunner;
import java.util.*;
import java.text.*;
/** /**
* Unit tests {@link org.apache.commons.lang.time.FastDateFormat}. * Unit tests {@link org.apache.commons.lang.time.FastDateFormat}.
* *
* @author Sean Schofield * @author Sean Schofield
* @since 2.0 * @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 { public class FastDateFormatTest extends TestCase {
@ -97,6 +100,7 @@ public void test_getInstance() {
FastDateFormat format1 = FastDateFormat.getInstance(); FastDateFormat format1 = FastDateFormat.getInstance();
FastDateFormat format2 = FastDateFormat.getInstance(); FastDateFormat format2 = FastDateFormat.getInstance();
assertSame(format1, format2); assertSame(format1, format2);
assertEquals(new SimpleDateFormat().toPattern(), format1.getPattern());
} }
public void test_getInstance_String() { public void test_getInstance_String() {
@ -104,64 +108,75 @@ public void test_getInstance_String() {
FastDateFormat format2 = FastDateFormat.getInstance("MM-DD-yyyy"); FastDateFormat format2 = FastDateFormat.getInstance("MM-DD-yyyy");
assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2);
assertSame(format1, FastDateFormat.getInstance("MM/DD/yyyy")); assertSame(format1, FastDateFormat.getInstance("MM/DD/yyyy"));
assertEquals("MM/DD/yyyy", format1.getPattern());
} }
public void test_getInstance_String_TimeZone() { public void test_getInstance_String_TimeZone() {
Locale realDefaultLocale = Locale.getDefault(); Locale realDefaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
TimeZone realDefaultZone = TimeZone.getDefault(); TimeZone realDefaultZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); try {
Locale.setDefault(Locale.US);
FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
TimeZone.getTimeZone("Atlantic/Reykjavik"));
FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy",
FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); TimeZone.getTimeZone("Atlantic/Reykjavik"));
FastDateFormat format4 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy");
FastDateFormat format5 = FastDateFormat.getInstance("MM-DD-yyyy", TimeZone.getDefault()); FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault());
FastDateFormat format4 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault());
assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); FastDateFormat format5 = FastDateFormat.getInstance("MM-DD-yyyy", TimeZone.getDefault());
assertTrue(format1.getTimeZone().equals(TimeZone.getTimeZone("Atlantic/Reykjavik")));
assertNull(format2.getTimeZone()); assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2);
assertSame(format3, format4); assertTrue(format1.getTimeZone().equals(TimeZone.getTimeZone("Atlantic/Reykjavik")));
assertTrue(format3 != format5); // -- junit 3.8 version -- assertFalse(format3 == format5); assertNull(format2.getTimeZone());
assertSame(format3, format4);
Locale.setDefault(realDefaultLocale); assertTrue(format3 != format5); // -- junit 3.8 version -- assertFalse(format3 == format5);
TimeZone.setDefault(realDefaultZone);
} finally {
Locale.setDefault(realDefaultLocale);
TimeZone.setDefault(realDefaultZone);
}
} }
public void test_getInstance_String_Locale() { public void test_getInstance_String_Locale() {
Locale realDefaultLocale = Locale.getDefault(); Locale realDefaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US); try {
FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); Locale.setDefault(Locale.US);
FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY);
FastDateFormat format3 = 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); assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2);
assertSame(format1, format3); assertSame(format1, format3);
assertSame(Locale.GERMANY, format1.getLocale()); assertSame(Locale.GERMANY, format1.getLocale());
Locale.setDefault(realDefaultLocale); } finally {
Locale.setDefault(realDefaultLocale);
}
} }
public void test_getInstance_String_TimeZone_Locale() { public void test_getInstance_String_TimeZone_Locale() {
Locale realDefaultLocale = Locale.getDefault(); Locale realDefaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
TimeZone realDefaultZone = TimeZone.getDefault(); TimeZone realDefaultZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); try {
Locale.setDefault(Locale.US);
FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
TimeZone.getTimeZone("Atlantic/Reykjavik"), Locale.GERMANY);
FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy",
FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getTimeZone("Atlantic/Reykjavik"), Locale.GERMANY);
TimeZone.getDefault(), Locale.GERMANY); FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY);
FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy",
assertTrue(format1 != format2); // -- junit 3.8 version -- assertNotSame(format1, format2); TimeZone.getDefault(), Locale.GERMANY);
assertEquals(format1.getTimeZone(), TimeZone.getTimeZone("Atlantic/Reykjavik"));
assertNull(format2.getTimeZone()); assertTrue(format1 != format2); // -- junit 3.8 version -- assertNotSame(format1, format2);
assertEquals(format3.getTimeZone(), TimeZone.getDefault()); assertEquals(format1.getTimeZone(), TimeZone.getTimeZone("Atlantic/Reykjavik"));
assertEquals(format3.getTimeZone(), TimeZone.getTimeZone("America/New_York")); assertNull(format2.getTimeZone());
assertEquals(format3.getTimeZone(), TimeZone.getDefault());
Locale.setDefault(realDefaultLocale); assertEquals(format3.getTimeZone(), TimeZone.getTimeZone("America/New_York"));
TimeZone.setDefault(realDefaultZone);
} finally {
Locale.setDefault(realDefaultLocale);
TimeZone.setDefault(realDefaultZone);
}
} }
} }