You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/07/06 08:52:40 UTC
svn commit: r1751629 -
/poi/trunk/src/testcases/org/apache/poi/util/TestLocaleUtil.java
Author: onealj
Date: Wed Jul 6 08:52:40 2016
New Revision: 1751629
URL: http://svn.apache.org/viewvc?rev=1751629&view=rev
Log:
bug 59805: add unit test for LocaleUtil#getLocaleCalendar
Modified:
poi/trunk/src/testcases/org/apache/poi/util/TestLocaleUtil.java
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestLocaleUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestLocaleUtil.java?rev=1751629&r1=1751628&r2=1751629&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestLocaleUtil.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestLocaleUtil.java Wed Jul 6 08:52:40 2016
@@ -20,20 +20,35 @@ package org.apache.poi.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
+import org.junit.Before;
import org.junit.Test;
public class TestLocaleUtil {
private static final Locale ja_JP = Locale.JAPAN;
private static final TimeZone TOKYO = TimeZone.getTimeZone("Asia/Tokyo");
+ private static final Calendar JAPAN_CALENDAR = Calendar.getInstance(TOKYO, ja_JP);
+
+ @Before
+ public void setUp() {
+ // clear the user locale and time zone so that tests do not interfere with each other
+ // the other way and better way would be to run each test in its own thread since
+ // LocaleUtil uses per-thread settings.
+ // Helpful, but not ASL 2.0 licensed:
+ // http://www.codeaffine.com/2014/07/21/a-junit-rule-to-run-a-test-in-its-own-thread/
+ LocaleUtil.setUserLocale(Locale.GERMANY);
+ LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
+ }
@Test
@SuppressForbidden("implementation around default locales in POI")
public void userLocale() {
Locale DEFAULT_LOCALE = LocaleUtil.getUserLocale();
+
assertEquals(DEFAULT_LOCALE, LocaleUtil.getUserLocale());
assertNotEquals(ja_JP, LocaleUtil.getUserLocale());
@@ -52,4 +67,33 @@ public class TestLocaleUtil {
LocaleUtil.setUserTimeZone(TOKYO);
assertEquals(TOKYO, LocaleUtil.getUserTimeZone());
}
+
+ @Test
+ @SuppressForbidden("implementation around default locales in POI")
+ public void localeCalendar() {
+ Locale DEFAULT_LOCALE = LocaleUtil.getUserLocale();
+ TimeZone DEFAULT_TIME_ZONE = LocaleUtil.getUserTimeZone();
+ Calendar DEFAULT_CALENDAR = LocaleUtil.getLocaleCalendar();
+
+ assertEquals(DEFAULT_LOCALE, LocaleUtil.getUserLocale());
+ assertEquals(DEFAULT_TIME_ZONE, LocaleUtil.getUserTimeZone());
+ assertCalendarEquals(DEFAULT_CALENDAR, LocaleUtil.getLocaleCalendar());
+ assertNotEquals(ja_JP, LocaleUtil.getUserLocale());
+ assertNotEquals(TOKYO, LocaleUtil.getUserTimeZone());
+ assertCalendarNotEquals(JAPAN_CALENDAR, LocaleUtil.getLocaleCalendar());
+
+ LocaleUtil.setUserLocale(ja_JP);
+ LocaleUtil.setUserTimeZone(TOKYO);
+ assertCalendarEquals(JAPAN_CALENDAR, LocaleUtil.getLocaleCalendar());
+ // FIXME: These might affect the time zone due to daylight savings:
+ //assertCalendarEquals(JAPAN_CALENDAR, LocaleUtil.getLocaleCalendar(2016, 01, 01));
+ //assertCalendarEquals(JAPAN_CALENDAR, LocaleUtil.getLocaleCalendar(2016, 01, 01, 00, 00, 00));
+ }
+
+ private static void assertCalendarNotEquals(Calendar expected, Calendar actual) {
+ assertNotEquals("time zone", expected.getTimeZone(), actual.getTimeZone());
+ }
+ private static void assertCalendarEquals(Calendar expected, Calendar actual) {
+ assertEquals("time zone", expected.getTimeZone(), actual.getTimeZone());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org