ICU-13703 Fixed TestHoliday/TestEaster test execution issue.

X-SVN-Rev: 41416
This commit is contained in:
Yoshito Umaoka 2018-05-20 18:47:57 +00:00
parent 8265a37aa4
commit 19eadbf90d
3 changed files with 33 additions and 16 deletions

View File

@ -154,8 +154,7 @@ class EasterRule implements DateRule {
public EasterRule(int daysAfterEaster, boolean isOrthodox) { public EasterRule(int daysAfterEaster, boolean isOrthodox) {
this.daysAfterEaster = daysAfterEaster; this.daysAfterEaster = daysAfterEaster;
if (isOrthodox) { if (isOrthodox) {
orthodox.setGregorianChange(new Date(Long.MAX_VALUE)); calendar.setGregorianChange(new Date(Long.MAX_VALUE));
calendar = orthodox;
} }
} }
@ -288,9 +287,6 @@ class EasterRule implements DateRule {
} }
} }
private static GregorianCalendar gregorian = new GregorianCalendar(/* new SimpleTimeZone(0, "UTC") */);
private static GregorianCalendar orthodox = new GregorianCalendar(/* new SimpleTimeZone(0, "UTC") */);
private int daysAfterEaster; private int daysAfterEaster;
private GregorianCalendar calendar = gregorian; private GregorianCalendar calendar = new GregorianCalendar();
} }

View File

@ -11,7 +11,6 @@ package com.ibm.icu.dev.test.calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -33,13 +32,14 @@ import com.ibm.icu.util.ULocale;
*/ */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class HolidayTest extends TestFmwk { public class HolidayTest extends TestFmwk {
@Before
public void init() throws Exception { // Do not use Before annotation, because TestFmwk's Before
if(cal==null){ // method must be executed first to initialize default time zone
cal = new GregorianCalendar(1, 0, 1); @Override
longTimeAgo = cal.getTime(); protected void localTestInitialize() {
now = new Date(); cal = new GregorianCalendar(1, 0, 1);
} longTimeAgo = cal.getTime();
now = new Date();
} }
private Calendar cal; private Calendar cal;

View File

@ -75,17 +75,38 @@ abstract public class TestFmwk extends AbstractTestLog {
} }
@Before @Before
public void testInitialize() { public final void testInitialize() {
Locale.setDefault(defaultLocale); Locale.setDefault(defaultLocale);
TimeZone.setDefault(defaultTimeZone); TimeZone.setDefault(defaultTimeZone);
if (getParams().testSecurityManager != null) { if (getParams().testSecurityManager != null) {
System.setSecurityManager(getParams().testSecurityManager); System.setSecurityManager(getParams().testSecurityManager);
} }
localTestInitialize();
}
/**
* This method is called at the end of {@link #testInitialize()}.
* Because JUnit does not guarantee the order of multiple Before
* methods, TestFmwk implementation class should override this
* method, instead of annotating Before.
*/
protected void localTestInitialize() {
}
/**
* This method is called at the beginning of {@link #testTeardown()}.
* TestFmwk implementation class hould override this method, instead
* of annotating After.
*/
protected void localTestTeardown() {
} }
@After @After
public void testTeardown() { public final void testTeardown() {
localTestTeardown();
if (getParams().testSecurityManager != null) { if (getParams().testSecurityManager != null) {
System.setSecurityManager(getParams().originalSecurityManager); System.setSecurityManager(getParams().originalSecurityManager);
} }