MagicListFunctions implements SpecialCommand { @Override public StellarResult execute(String command, StellarShellExecutor executor) { String startsWith = StringUtils.trimToEmpty(command.substring(MAGIC_FUNCTIONS.length())); Predicate<String> nameFilter = (name -> true); if (StringUtils.isNotBlank(startsWith)) { nameFilter = (name -> name.contains(startsWith)); } String functions = StreamSupport .stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false) .map(info -> String.format("%s", info.getName())) .filter(nameFilter) .sorted() .collect(Collectors.joining(", ")); return StellarResult.success(functions); }  @Override String getCommand(); @Override Function<String, Boolean> getMatcher(); @Override StellarResult execute(String command, StellarShellExecutor executor); static final String MAGIC_FUNCTIONS; }
@Test public void testFunctions() { StellarResult result = magic.execute("%functions", executor); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); String value = ConversionUtils.convert(result.getValue().get(), String.class); String[] functions = value.split(", "); assertEquals(3, functions.length); }
@Test public void testFunctionsWithMatch() { StellarResult result = magic.execute("%functions UPPER", executor); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); String value = ConversionUtils.convert(result.getValue().get(), String.class); String[] functions = value.split(", "); assertEquals(1, functions.length); assertEquals("TO_UPPER", functions[0]); }
@Test public void testFunctionsWithNoMatch() { StellarResult result = magic.execute("%functions NOMATCH", executor); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); String value = ConversionUtils.convert(result.getValue().get(), String.class); String[] functions = value.trim().split(", "); assertEquals(1, functions.length); assertEquals("", functions[0]); }