### Question:
StringToTimestamp implements Kudf { @Override public Object evaluate(final Object... args) { if (args.length != 2) { throw new KsqlFunctionException("StringToTimestamp udf should have two input argument:" + " date value and format."); } try { ensureInitialized(args); return timestampParser.parse(args[0].toString()); } catch (final Exception e) { throw new KsqlFunctionException("Exception running StringToTimestamp(" + args[0] + ", " + args[1] + ") : " + e.getMessage(), e); } }  @Override Object evaluate(final Object... args);  }### Answer:
@Test public void shouldCovertStringToTimestamp() throws ParseException { final Object result = udf.evaluate("2021-12-01 12:10:11.123", "yyyy-MM-dd HH:mm:ss.SSS"); long expectedResult = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") .parse("2021-12-01 12:10:11.123").getTime(); assertThat(result, is(expectedResult)); }
@Test public void shouldSupportEmbeddedChars() throws ParseException { final Object result = udf.evaluate("2021-12-01T12:10:11.123Fred", "yyyy-MM-dd'T'HH:mm:ss.SSS'Fred'"); long expectedResult = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Fred'") .parse("2021-12-01T12:10:11.123Fred").getTime(); assertThat(result, is(expectedResult)); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfTooFewParameters() { udf.evaluate("2021-12-01 12:10:11.123"); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowIfTooManyParameters() { udf.evaluate("2021-12-01 12:10:11.123", "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 shouldThrowIfParseFails() { udf.evaluate("invalid", "yyyy-MM-dd'T'HH:mm:ss.SSS"); }
@Test(expected = KsqlFunctionException.class) public void shouldThrowOnEmptyString() { udf.evaluate("invalid", "yyyy-MM-dd'T'HH:mm:ss.SSS"); }
@Test public void shouldBeThreadSafe() { IntStream.range(0, 10_000) .parallel() .forEach(idx -> { try { shouldCovertStringToTimestamp(); } catch (ParseException e) { Assert.fail(e.getMessage()); } udf.evaluate("1988-01-12 10:12:13.456", "yyyy-MM-dd HH:mm:ss.SSS"); }); }