### Question:
LogicalStartTimeMacro { public String evaluate(long logicalStartTime, String... arguments) { if (arguments.length == 1 && arguments[0].isEmpty()) { return String.valueOf(logicalStartTime); } SimpleDateFormat dateFormat; long offset = 0; TimeZone timeZone = defaultTimeZone; if (arguments.length > 3) { throw new IllegalArgumentException("runtime macro supports at most 3 arguments - format, offset, and timezone. " + "Formats containing a comma are not supported."); } dateFormat = new SimpleDateFormat(arguments[0]); if (arguments.length > 1) { TimeParser timeParser = new TimeParser(logicalStartTime); offset = timeParser.parseRuntime(arguments[1].trim()); if (arguments.length > 2) { timeZone = TimeZone.getTimeZone(arguments[2].trim()); } } dateFormat.setTimeZone(timeZone); Date date = new Date(logicalStartTime - offset); return dateFormat.format(date); } LogicalStartTimeMacro(); @VisibleForTesting  LogicalStartTimeMacro(TimeZone defaultTimeZone); String evaluate(long logicalStartTime, String... arguments);  }### Answer:
@Test public void testSubstitution() { LogicalStartTimeMacro runtimeMacro = new LogicalStartTimeMacro(TimeZone.getTimeZone("UTC")); long logicalStartTime = 0; Assert.assertEquals("0", runtimeMacro.evaluate(logicalStartTime, "")); Assert.assertEquals("1970-01-01", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd")); Assert.assertEquals("1969-12-31", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd", "1d")); Assert.assertEquals("1969-12-31", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd", "+1d")); Assert.assertEquals("1970-01-02", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd", "-1d")); logicalStartTime = 1451606400000L; Assert.assertEquals("2016-01-01", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd")); Assert.assertEquals("2015-12-31", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd", "1d")); Assert.assertEquals("2015-12-31T00:00:00", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd'T'HH:mm:ss", "1d")); Assert.assertEquals("2015-12-31T12:00:00", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd'T'HH:mm:ss", "1d-12h")); Assert.assertEquals("2015-12-31T11:29:45", runtimeMacro.evaluate(logicalStartTime, "yyyy-MM-dd'T'HH:mm:ss", "1d-12h+30m+15s")); }
@Test public void testOffset() { LogicalStartTimeMacro runtimeMacro = new LogicalStartTimeMacro(TimeZone.getTimeZone("UTC")); Assert.assertEquals("1969-12-31T23:30:00", runtimeMacro.evaluate(0, "yyyy-MM-dd'T'HH:mm:ss", "30m")); }
@Test public void testTimeZone() { LogicalStartTimeMacro runtimeMacro = new LogicalStartTimeMacro(TimeZone.getTimeZone("PST")); Assert.assertEquals("1969-12-31T15:30:00", runtimeMacro.evaluate(0, "yyyy-MM-dd'T'HH:mm:ss", "30m", "PST ")); }