### Question:
GroovyTemplateUtils { public static String renderTemplate(String template, Map<String, Object> newContext) throws IOException, ClassNotFoundException { Map<String, Object> contextMap = getDefaultContextMap(); contextMap.putAll(newContext); return GROOVY_TEMPLATE_ENGINE.createTemplate(template).make(contextMap).toString(); }  static String renderTemplate(String template, Map<String, Object> newContext); static Map<String, Object> getDefaultContextMap(); static Map<String, Object> getTemplateContext(List<String> values); static String renderTemplate(String template);  }### Answer:
@Test public void testDefaultRenderTemplate() throws IOException, ClassNotFoundException { Date today = new Date(Instant.now().toEpochMilli()); Date yesterday = new Date(Instant.now().minus(1, ChronoUnit.DAYS).toEpochMilli()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("${ today }"), dateFormat.format(today)); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("${ yesterday }"), dateFormat.format(yesterday)); }
@Test public void testRenderTemplateWithGivenContextMap() throws IOException, ClassNotFoundException { Map<String, Object> contextMap = new HashMap<>(); contextMap.put("first_date_2020", "2020-01-01"); contextMap.put("name", "xiang"); contextMap.put("ts", 1577836800); contextMap.put("yyyy", "2020"); contextMap.put("YYYY", "1919"); contextMap.put("MM", "05"); contextMap.put("dd", "06"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("$first_date_2020", contextMap), "2020-01-01"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("${first_date_2020}", contextMap), "2020-01-01"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("${ name }", contextMap), "xiang"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("${ ts }", contextMap), "1577836800"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("/var/rawdata/${ yyyy }/${ MM }/${ dd }", contextMap), "/var/rawdata/2020/05/06"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("/var/rawdata/${yyyy}/${MM}/${dd}", contextMap), "/var/rawdata/2020/05/06"); Assert.assertEquals(GroovyTemplateUtils.renderTemplate("/var/rawdata/${YYYY}/${MM}/${dd}", contextMap), "/var/rawdata/1919/05/06"); }