FormatFunction { @FunctionMeta(description = "Format number with message pattern with auto scaling", example = "${w:formatNumber(12345, '0.#', 'B')}") public static String formatNumber(Number data, String pattern, String suffix) { return Formats.forNumber().format(data, pattern, suffix); }  @FunctionMeta(description = "Format object using message pattern", example = "${w:format(payload.dateFrom,'yyyy-MM-dd')}") static String format(Object obj, String pattern); @FunctionMeta(description = "Format number with message pattern with auto scaling", example = "${w:formatNumber(12345, '0.#', 'B')}") static String formatNumber(Number data, String pattern, String suffix); @FunctionMeta(description = "Format number in percentage", example = "${w:percentage(4, 11, 2)}") static String percentage(int divisor, int divident, int precision); @FunctionMeta(description = "Shorten a message", example = "${w:shorten('123456789', 5)} will be '1...9'") static String shorten(String str, int maxLength);  }
@Test public void testFormatNumber() { Assert.assertEquals("12.1KB", FormatFunction.formatNumber(12344, "0.#", "B")); Assert.assertEquals("12.05Kb", FormatFunction.formatNumber(12344, "0.0#", "b")); Assert.assertEquals("12.34s", FormatFunction.formatNumber(12.344, "0.##", "s")); Assert.assertEquals("123.4ms", FormatFunction.formatNumber(0.12344, "0.#", "s")); Assert.assertEquals("123.4us", FormatFunction.formatNumber(0.00012344, "0.#", "s")); }