title: Convert ISO DateTime to XMLGregorianCalendar and verify using JUnits
body: <p>I'm having a util method that converts ISO Date Format into XMLGregorianCalendar. </p>
  
  <p>I'm trying to write unit test cases for it, however, I'm unable to create the expected object as that of the actual - there is time zone conversion happening in between and the objects are not matching.</p>
  
  <pre><code> public static XMLGregorianCalendar convertStringToXMLGregorianCalendar(final String dateStrInXMLGregorianCalendar) {
          try {
              DateTime dateTime = ISODateTimeFormat.dateTime().parseDateTime(dateStrInXMLGregorianCalendar);
              GregorianCalendar gregCal = new GregorianCalendar(dateTime.getZone().toTimeZone());
              gregCal.setTimeInMillis(dateTime.getMillis());
              return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCal);
          } catch (Exception e) {
              throw new RuntimeException(String.format("Exception while converting %s to XMLGregorianCalendar!", dateStrInXMLGregorianCalendar), e);
          }
   }
  </code></pre>
  
  <p>JUnit:</p>
  
  <pre><code>@Test
  public void testFoo() throws Exception {
  
       XMLGregorianCalendar result = convertStringToXMLGregorianCalendar("2016-02-06T00:00:00.000+0100");
       assertNotNull(result);
       assertTrue(result.toGregorianCalendar().toZonedDateTime().toLocalDateTime().compareTo(
                  DatatypeFactory.newInstance().newXMLGregorianCalendar(2016, 2, 6, 0, 0, 0, 0, 0).toGregorianCalendar().toZonedDateTime().toLocalDateTime()) == 0);
  }
  </code></pre>