/** Test method for {@link EvaluatorBag#getDateFormatEvaluator()}. */ @Test public void testGetDateFormatEvaluator() { Evaluator dateFormatEval = EvaluatorBag.getDateFormatEvaluator(); ContextImpl context = new ContextImpl(null, resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP, null, null); Context.CURRENT_CONTEXT.set(context); try { Calendar calendar = new GregorianCalendar(); calendar.add(Calendar.DAY_OF_YEAR, -2); assertEquals( new SimpleDateFormat("yyyy-MM-dd HH:mm").format(calendar.getTime()), dateFormatEval.evaluate("'NOW-2DAYS','yyyy-MM-dd HH:mm'", Context.CURRENT_CONTEXT.get())); calendar = new GregorianCalendar(); Date date = calendar.getTime(); Map<String, Object> map = new HashMap<String, Object>(); map.put("key", date); resolver.addNamespace("A", map); assertEquals( new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date), dateFormatEval.evaluate("A.key, 'yyyy-MM-dd HH:mm'", Context.CURRENT_CONTEXT.get())); } finally { Context.CURRENT_CONTEXT.remove(); } }
private void runTests(Map<String, String> tests, Evaluator evaluator) { ContextImpl ctx = new ContextImpl(null, resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP, null, null); Context.CURRENT_CONTEXT.set(ctx); try { for (Map.Entry<String, String> entry : tests.entrySet()) { Map<String, Object> values = new HashMap<String, Object>(); values.put("key", entry.getKey()); resolver.addNamespace("A", values); String expected = (String) entry.getValue(); String actual = evaluator.evaluate("A.key", ctx); assertEquals(expected, actual); } } finally { Context.CURRENT_CONTEXT.remove(); } }