### Question:
JsonUtils { public static String formatDateRfc822(Date date, String timeZoneId) { if (date != null) { TimeZone tZone = "GMT".equals(timeZoneId) ? GMT_TZ : TimeZone.getTimeZone(timeZoneId); SimpleDateFormat dateFormater = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); dateFormater.setTimeZone(tZone); return dateFormater.format(date); } return null; }  static String formatDateRfc822(Date date, String timeZoneId); static String formatDateRfc822(Date date); static Date parseDateRfc822(String str);  }### Answer:
@Test public void testValidNonGMTTimeZone() throws Exception { String gmtTime = "Thu, 01 Jan 2009 08:00:00 GMT"; SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); Date date = dateFormatter.parse(gmtTime); String pstTime = JsonUtils.formatDateRfc822(date, "PST"); assertEquals(pstTime, "Thu, 01 Jan 2009 00:00:00 PST"); }
@Test public void testInvalidTimeZone() throws Exception { String gmtTime = "Thu, 01 Jan 2009 00:00:00 GMT"; SimpleDateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); Date date = dateFormatter.parse(gmtTime); String asdTime = JsonUtils.formatDateRfc822(date, "ASD"); assertEquals(asdTime, gmtTime); }
@Test public void testNullDate() { assertEquals(null, JsonUtils.formatDateRfc822(null)); }