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));
}
}
}
}
- 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();
}
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;
*/
@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;
}
@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);
}