I am looking for a solution for testing these methods especially for date util classes. I am adding my two methods that I want to write a test for. How can I call the method at the end and how to doReturn the XMLGregorianCalendar when it has nested returns inside like the method I added?
public static XMLGregorianCalendar getCalendar() throws DatatypeConfigurationException {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
XMLGregorianCalendar gdateFormatted =
DatatypeFactory.newInstance().newXMLGregorianCalendar(format.format(DateUtils.currentDate()));
return gdateFormatted;
}
public static String getDateNowYyMm() throws DatatypeConfigurationException {
DateFormat format = new SimpleDateFormat("yyMM");
XMLGregorianCalendar gdateFormatted =
DatatypeFactory.newInstance().newXMLGregorianCalendar(format.format(DateUtils.currentDate()));
return gdateFormatted.toString();
}
My problem has been resolved, my test method is below:
public void getCalendarTest() throws DatatypeConfigurationException {
XMLGregorianCalendar gdateFormatted = DateUtils.getCalendar();
Assert.assertNotNull(gdateFormatted);
}
I couldn't succeed the part of XMLGregorianCalendar.