Permalink
Browse files

Make tests locale independe.t

  • Loading branch information...
1 parent baa7969 commit 74e7f77b05ce998e6db1b51a9864cf449da39ce7 @nbeloglazov nbeloglazov committed Mar 4, 2012
View
@@ -1,6 +1,8 @@
.classpath
.settings
.project
+.idea
+*.iml
bin
target
src/main/java/com/joestelmach/natty/generated/*
@@ -2,22 +2,31 @@
import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.List;
+import java.util.TimeZone;
import org.junit.Assert;
import org.junit.Before;
import com.joestelmach.natty.CalendarSource;
import com.joestelmach.natty.Parser;
+import org.junit.BeforeClass;
/**
*
* @author Joe Stelmach
*/
public abstract class AbstractTest {
- private static final Calendar _calendar = Calendar.getInstance();
- protected static final Parser _parser = new Parser();
-
+ private static Calendar _calendar;
+ protected static Parser _parser;
+
+
+ public static void initCalendarAndParser() {
+ _calendar = Calendar.getInstance();
+ _parser = new Parser();
+ }
+
/**
* Resets the calendar source time before each test
*/
@@ -141,7 +150,7 @@ protected void validateDateTime(String value, int month, int day, int year,
*/
protected void validateDateTime(Date date, int month, int day, int year,
int hours, int minutes, int seconds) {
-
+
_calendar.setTime(date);
Assert.assertEquals(month -1, _calendar.get(Calendar.MONTH));
Assert.assertEquals(day, _calendar.get(Calendar.DAY_OF_MONTH));
@@ -4,6 +4,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.logging.ConsoleHandler;
@@ -23,7 +24,9 @@
public class DateTest extends AbstractTest {
@BeforeClass
public static void oneTime() {
+ Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern"));
+ initCalendarAndParser();
}
@Test
@@ -3,6 +3,7 @@
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.TimeZone;
import org.junit.Assert;
@@ -17,7 +18,9 @@
public class DateTimeTest extends AbstractTest {
@BeforeClass
public static void oneTime() {
+ Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern"));
+ initCalendarAndParser();
}
@Test
@@ -2,6 +2,7 @@
import java.text.DateFormat;
import java.util.Date;
+import java.util.Locale;
import java.util.TimeZone;
import org.junit.BeforeClass;
@@ -12,7 +13,9 @@
@BeforeClass
public static void oneTime() {
+ Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern"));
+ initCalendarAndParser();
}
@Test
@@ -3,6 +3,7 @@
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.TimeZone;
import org.junit.Assert;
@@ -17,7 +18,9 @@
public class TimeTest extends AbstractTest {
@BeforeClass
public static void oneTime() {
+ Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("US/Eastern"));
+ initCalendarAndParser();
}
/**

0 comments on commit 74e7f77

Please sign in to comment.