title: How to set the timezone for a SimpleDateFormat in Android Unit test
body: <p>I want to test a method in a Date utility class that gets a <code>Date</code> from a String. The String that is passed is <code>1980-03-26T00:00:00.000+0200</code> and I want to compare the resulting date with <code>assertEquals</code>. The test failed with this output:</p>
  
  <pre><code>org.junit.ComparisonFailure: 
  Expected :Wed Mar 26 00:00:00 PST 1980
  Actual   :Wed Mar 26 00:00:00 SGT 1980
  </code></pre>
  
  <p>Here's my test:</p>
  
  <pre><code>INITIAL_DATA_DATE_FROM_STRING = "1980-03-26T00:00:00.000+0200";
  EXPECTED_DATA_DATE_FROM_STRING = "Wed Mar 26 00:00:00 PST 1980";
  
  // inside the method ...
  
  date = DateUtils.getDateFromString(INITIAL_DATA_DATE_FROM_STRING);
  assertEquals(EXPECTED_DATA_DATE_FROM_STRING, String.valueOf(date));
  </code></pre>
  
  <p>Here's the method that I am testing:</p>
  
  <pre><code>    public static Date getDateFromString(String dateAsString) {
          return getDateFromString(dateAsString, "dd/MM/yyyy");
      }
  
      public static Date getDateFromString(String dateAsString, String dateFormat) {
          Date formattedDate = null;
          if (StringUtils.notNull(dateAsString)) {
              DateFormat format = new SimpleDateFormat(dateFormat);
              try {
                  formattedDate = parseString(dateAsString, format);
              } catch (ParseException e) {
                  try {
                      formattedDate = parseString(dateAsString, new SimpleDateFormat("yyyy-MM-dd"));
                  } catch (ParseException e1) {
                      // handle exception code
                  }
              }
          }
          return formattedDate;
      }
  </code></pre>
  
  <p>So the unit test is not timezone independent. Is there anyway to set the default timezone just for unit testing?</p>