HL7TemplateFunctions { public String formatDate(Date date, String format){ String dateString; SimpleDateFormat dateFormat = null; if(date == null) date = new Date(); if(format != null){ dateFormat = new SimpleDateFormat(format); }else{ dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); } dateString = dateFormat.format(date); return dateString; }  void setHl7queryService(HL7QueryService hl7queryService); void setAdminService(AdministrationService adminService); String evaluateTemplate(String templateName, Map<String, Object> bindings); String getGlobalProperty(String globalPropertyName); String getImplementationId(); String formatDate(Date date, String format); Set<Obs> getObsGroups(Encounter encounter); Concept getMedicalRecordObservationsConcept(); String getUnits(Concept concept); static Log log; }
@Test public void formatDate_shouldCreateNewDateIfInputDateIsNull() throws Exception { HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertNotNull(functions.formatDate(null, null)); }
@Test public void formatDate_shouldUseDefaultDateFormatIfInputDateFormatIsNull() throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date testDate = new Date(); String dateString = dateFormat.format(testDate); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals(dateString, functions.formatDate(testDate, null)); }
@Test public void formatDate_shouldUseInputDateFormatToFormatDate() throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Date testDate = new Date(); String dateString = dateFormat.format(testDate); HL7TemplateFunctions functions = new HL7TemplateFunctions(); Assert.assertEquals(dateString, functions.formatDate(testDate, "yyyyMMdd")); }