### Question:
TimestampToString implements Kudf { @Override public Object evaluate(Object... args) { if (args.length != 2) { throw new KsqlFunctionException("TimestampToString udf should have two input argument:" + " date value and format."); } try { ensureInitialized(args); final Timestamp timestamp = new Timestamp((Long) args[0]); return timestamp.toLocalDateTime() .atZone(ZoneId.systemDefault()) .format(threadSafeFormatter); } catch (Exception e) { throw new KsqlFunctionException("Exception running TimestampToString(" + args[0] + " , " + args[1] + ") : " + e.getMessage(), e); } }  @Override Object evaluate(Object... args);  }### Answer:
@Test public void shouldCovertTimestampToString() { final Object result = udf.evaluate(1638360611123L, "yyyy-MM-dd HH:mm:ss.SSS"); String expectedResult = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") .format(new Date(1638360611123L)); assertThat(result, is(expectedResult)); }
@Test public void shouldSupportEmbeddedChars() { final Object result = udf.evaluate(1638360611123L, "yyyy-MM-dd'T'HH:mm:ss.SSS'Fred'"); String expectedResult = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Fred'") .format(new Date(1638360611123L)); assertThat(result, is(expectedResult)); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfTooFewParameters() { udf.evaluate(1638360611123L); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfTooManyParameters() { udf.evaluate(1638360611123L, "yyyy-MM-dd HH:mm:ss.SSS", "extra"); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfFormatInvalid() { udf.evaluate("2021-12-01 12:10:11.123", "invalid"); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfNotTimestamp() { udf.evaluate("invalid", "2021-12-01 12:10:11.123"); }
@Test public void shouldBeThreadSafe() { IntStream.range(0, 10_000) .parallel() .forEach(idx -> { shouldCovertTimestampToString(); udf.evaluate(1538361611123L, "yyyy-MM-dd HH:mm:ss.SSS"); }); }