Fixes issue 3464, DateBox cannot be mocked. 

Reviewed by jgw



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@4995 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
index f5c9edf..65f0380 100644
--- a/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
+++ b/user/src/com/google/gwt/i18n/client/DateTimeFormat.java
@@ -406,8 +406,6 @@
   private static DateTimeFormat cachedShortDateTimeFormat;
 
   private static final int NUM_MILLISECONDS_IN_DAY = 24 * 60 * 60000;
-  private static final DateTimeConstants defaultDateTimeConstants = LocaleInfo.getCurrentLocale().getDateTimeConstants();
-
   private static final String PATTERN_CHARS = "GyMdkHmsSEDahKzZv";
 
   private static final String NUMERIC_FORMAT_CHARS = "MydhHmsSDkK";
@@ -433,7 +431,11 @@
    *           parsed
    */
   public static DateTimeFormat getFormat(String pattern) {
-    return new DateTimeFormat(pattern, defaultDateTimeConstants);
+    return new DateTimeFormat(pattern, getDefaultDateTimeConstants());
+  }
+
+  private static DateTimeConstants getDefaultDateTimeConstants() {
+    return LocaleInfo.getCurrentLocale().getDateTimeConstants();
   }
 
   /**
@@ -444,7 +446,7 @@
    */
   public static DateTimeFormat getFullDateFormat() {
     if (cachedFullDateFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[FULL_DATE_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[FULL_DATE_FORMAT];
       cachedFullDateFormat = new DateTimeFormat(pattern);
     }
     return cachedFullDateFormat;
@@ -458,8 +460,8 @@
    */
   public static DateTimeFormat getFullDateTimeFormat() {
     if (cachedFullDateTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[FULL_DATE_FORMAT]
-          + " " + defaultDateTimeConstants.timeFormats()[FULL_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[FULL_DATE_FORMAT]
+          + " " + getDefaultDateTimeConstants().timeFormats()[FULL_TIME_FORMAT];
       cachedFullDateTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedFullDateTimeFormat;
@@ -473,7 +475,7 @@
    */
   public static DateTimeFormat getFullTimeFormat() {
     if (cachedFullTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.timeFormats()[FULL_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().timeFormats()[FULL_TIME_FORMAT];
       cachedFullTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedFullTimeFormat;
@@ -487,7 +489,7 @@
    */
   public static DateTimeFormat getLongDateFormat() {
     if (cachedLongDateFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[LONG_DATE_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[LONG_DATE_FORMAT];
       cachedLongDateFormat = new DateTimeFormat(pattern);
     }
     return cachedLongDateFormat;
@@ -501,8 +503,8 @@
    */
   public static DateTimeFormat getLongDateTimeFormat() {
     if (cachedLongDateTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[LONG_DATE_FORMAT]
-          + " " + defaultDateTimeConstants.timeFormats()[LONG_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[LONG_DATE_FORMAT]
+          + " " + getDefaultDateTimeConstants().timeFormats()[LONG_TIME_FORMAT];
       cachedLongDateTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedLongDateTimeFormat;
@@ -516,7 +518,7 @@
    */
   public static DateTimeFormat getLongTimeFormat() {
     if (cachedLongTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.timeFormats()[LONG_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().timeFormats()[LONG_TIME_FORMAT];
       cachedLongTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedLongTimeFormat;
@@ -530,7 +532,7 @@
    */
   public static DateTimeFormat getMediumDateFormat() {
     if (cachedMediumDateFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[MEDIUM_DATE_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[MEDIUM_DATE_FORMAT];
       cachedMediumDateFormat = new DateTimeFormat(pattern);
     }
     return cachedMediumDateFormat;
@@ -544,8 +546,8 @@
    */
   public static DateTimeFormat getMediumDateTimeFormat() {
     if (cachedMediumDateTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[MEDIUM_DATE_FORMAT]
-          + " " + defaultDateTimeConstants.timeFormats()[MEDIUM_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[MEDIUM_DATE_FORMAT]
+          + " " + getDefaultDateTimeConstants().timeFormats()[MEDIUM_TIME_FORMAT];
       cachedMediumDateTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedMediumDateTimeFormat;
@@ -559,7 +561,7 @@
    */
   public static DateTimeFormat getMediumTimeFormat() {
     if (cachedMediumTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.timeFormats()[MEDIUM_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().timeFormats()[MEDIUM_TIME_FORMAT];
       cachedMediumTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedMediumTimeFormat;
@@ -573,7 +575,7 @@
    */
   public static DateTimeFormat getShortDateFormat() {
     if (cachedShortDateFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[SHORT_DATE_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[SHORT_DATE_FORMAT];
       cachedShortDateFormat = new DateTimeFormat(pattern);
     }
     return cachedShortDateFormat;
@@ -587,8 +589,8 @@
    */
   public static DateTimeFormat getShortDateTimeFormat() {
     if (cachedShortDateTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.dateFormats()[SHORT_DATE_FORMAT]
-          + " " + defaultDateTimeConstants.timeFormats()[SHORT_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().dateFormats()[SHORT_DATE_FORMAT]
+          + " " + getDefaultDateTimeConstants().timeFormats()[SHORT_TIME_FORMAT];
       cachedShortDateTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedShortDateTimeFormat;
@@ -602,7 +604,7 @@
    */
   public static DateTimeFormat getShortTimeFormat() {
     if (cachedShortTimeFormat == null) {
-      String pattern = defaultDateTimeConstants.timeFormats()[SHORT_TIME_FORMAT];
+      String pattern = getDefaultDateTimeConstants().timeFormats()[SHORT_TIME_FORMAT];
       cachedShortTimeFormat = new DateTimeFormat(pattern);
     }
     return cachedShortTimeFormat;
@@ -621,7 +623,7 @@
    * @param pattern string pattern specification
    */
   protected DateTimeFormat(String pattern) {
-    this(pattern, defaultDateTimeConstants);
+    this(pattern, getDefaultDateTimeConstants());
   }
 
   /**
diff --git a/user/src/com/google/gwt/user/datepicker/client/CalendarModel.java b/user/src/com/google/gwt/user/datepicker/client/CalendarModel.java
index d38dd0b..943230d 100644
--- a/user/src/com/google/gwt/user/datepicker/client/CalendarModel.java
+++ b/user/src/com/google/gwt/user/datepicker/client/CalendarModel.java
@@ -39,12 +39,6 @@
 

   private static final String[] dayOfWeekNames = new String[7];

 

-  private static final DateTimeFormat dayOfMonthFormatter = DateTimeFormat.getFormat("d");

-

-  private static final DateTimeFormat dayOfWeekFormatter = DateTimeFormat.getFormat("ccccc");

-

-  private static final DateTimeFormat monthAndYearFormatter = DateTimeFormat.getFormat("MMM yyyy");

-

   private static String[] dayOfMonthNames = new String[32];

 

   private final Date currentMonth;

@@ -171,7 +165,7 @@
    * @return the day of month formatter

    */

   protected DateTimeFormat getDayOfMonthFormatter() {

-    return dayOfMonthFormatter;

+    return DateTimeFormat.getFormat("d");

   }

 

   /**

@@ -180,7 +174,7 @@
    * @return the day of week formatter

    */

   protected DateTimeFormat getDayOfWeekFormatter() {

-    return dayOfWeekFormatter;

+    return DateTimeFormat.getFormat("ccccc");

   }

 

   /**

@@ -189,7 +183,7 @@
    * @return the month and year formatter

    */

   protected DateTimeFormat getMonthAndYearFormatter() {

-    return monthAndYearFormatter;

+    return DateTimeFormat.getFormat("MMM yyyy");

   }

 

   /**

diff --git a/user/src/com/google/gwt/user/datepicker/client/DateBox.java b/user/src/com/google/gwt/user/datepicker/client/DateBox.java
index 334a7a0..610851f 100644
--- a/user/src/com/google/gwt/user/datepicker/client/DateBox.java
+++ b/user/src/com/google/gwt/user/datepicker/client/DateBox.java
@@ -16,6 +16,7 @@
 
 package com.google.gwt.user.datepicker.client;
 
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.event.dom.client.BlurEvent;
 import com.google.gwt.event.dom.client.BlurHandler;
 import com.google.gwt.event.dom.client.ClickEvent;
@@ -239,7 +240,8 @@
    * Default style name.
    */
   public static final String DEFAULT_STYLENAME = "gwt-DateBox";
-  private static final DefaultFormat DEFAULT_FORMAT = new DefaultFormat();
+  private static final DefaultFormat DEFAULT_FORMAT = 
+    GWT.create(DefaultFormat.class);
   private final PopupPanel popup;
   private final TextBox box = new TextBox();
   private final DatePicker picker;
diff --git a/user/test/com/google/gwt/user/ClassInitTest.java b/user/test/com/google/gwt/user/ClassInitTest.java
index 8939c5f..7b08bc0 100644
--- a/user/test/com/google/gwt/user/ClassInitTest.java
+++ b/user/test/com/google/gwt/user/ClassInitTest.java
@@ -22,10 +22,10 @@
 import java.io.File;
 
 /**
- * Tests that every class in com.google.gwt.user.client.ui can be init'd by the
- * real Java runtime. By ensuring this, we ensure that these classes all may be
- * referenced mocked out by pure Java unit tests, e.g. with EasyMock Class
- * Extension
+ * Tests that every class in com.google.gwt.user.client.ui and
+ * com.google.gwt.user.datepicker.client can be init'd by the real Java
+ * runtime. By ensuring this, we ensure that these classes all may be referenced
+ * mocked out by pure Java unit tests, e.g. with EasyMock Class Extension
  */
 public class ClassInitTest extends TestCase {
   private static final String DOT_CLASS = ".class";
@@ -41,8 +41,15 @@
     GWTMockUtilities.restore();
   }
 
-  public void testOne() throws ClassNotFoundException {
-    String packageName = "com.google.gwt.user.client.ui";
+  public void testUi() throws ClassNotFoundException {
+    doPackage("com.google.gwt.user.client.ui");
+  }
+  
+  public void testDatePicker() throws ClassNotFoundException {
+    doPackage("com.google.gwt.user.datepicker.client");
+  }
+  
+  private void doPackage(String packageName) throws ClassNotFoundException {
     String path = packageNameToPath(packageName);
     File directory = pathToResourceDirectory(path);