]> granicus.if.org Git - icu/commitdiff
ICU-13703 Fixed TestHoliday/TestEaster test execution issue.
authorYoshito Umaoka <y.umaoka@gmail.com>
Sun, 20 May 2018 18:47:57 +0000 (18:47 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Sun, 20 May 2018 18:47:57 +0000 (18:47 +0000)
X-SVN-Rev: 41416

icu4j/main/classes/core/src/com/ibm/icu/util/EasterHoliday.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/HolidayTest.java
icu4j/main/tests/framework/src/com/ibm/icu/dev/test/TestFmwk.java

index f950a8b05f173283815fc13396a4c147a3901ced..702ce226c71a04e61c7e877306aa6f7720d59d34 100644 (file)
@@ -154,8 +154,7 @@ class EasterRule implements DateRule {
     public EasterRule(int daysAfterEaster, boolean isOrthodox) {
         this.daysAfterEaster = daysAfterEaster;
         if (isOrthodox) {
-            orthodox.setGregorianChange(new Date(Long.MAX_VALUE));
-            calendar = orthodox;
+            calendar.setGregorianChange(new Date(Long.MAX_VALUE));
         }
     }
 
@@ -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 GregorianCalendar calendar = gregorian;
+    private GregorianCalendar calendar = new GregorianCalendar();
 }
index ac1425eaead130e2859be6db2697db953b9369fd..d76b644e4bc94ef95ac32947097305f7e1e1e11b 100644 (file)
@@ -11,7 +11,6 @@ package com.ibm.icu.dev.test.calendar;
 import java.util.Date;
 import java.util.Locale;
 
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -33,13 +32,14 @@ import com.ibm.icu.util.ULocale;
  */
 @RunWith(JUnit4.class)
 public class HolidayTest extends TestFmwk {
-    @Before
-    public void init() throws Exception {
-        if(cal==null){
-            cal = new GregorianCalendar(1, 0, 1);
-            longTimeAgo = cal.getTime();
-            now = new Date();
-        }
+
+    // Do not use Before annotation, because TestFmwk's Before
+    // method must be executed first to initialize default time zone
+    @Override
+    protected void localTestInitialize() {
+        cal = new GregorianCalendar(1, 0, 1);
+        longTimeAgo = cal.getTime();
+        now = new Date();
     }
 
     private Calendar cal;
index ce0082eddbd3444114a8f2a4fc30c47dd0fb9929..5871b6a8de9f9c19717e9c830ccce287ed1e6129 100644 (file)
@@ -75,17 +75,38 @@ abstract public class TestFmwk extends AbstractTestLog {
     }
 
     @Before
-    public void testInitialize() {
+    public final void testInitialize() {
         Locale.setDefault(defaultLocale);
         TimeZone.setDefault(defaultTimeZone);
 
         if (getParams().testSecurityManager != null) {
             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
-    public void testTeardown() {
+    public final void testTeardown() {
+        localTestTeardown();
+
         if (getParams().testSecurityManager != null) {
             System.setSecurityManager(getParams().originalSecurityManager);
         }