DocCommand implements SpecialCommand { @Override public StellarResult execute(String command, StellarShellExecutor executor) { StellarResult result; String functionName = StringUtils.substring(command, 1); Spliterator<StellarFunctionInfo> fnIterator = executor.getFunctionResolver().getFunctionInfo().spliterator(); Optional<StellarFunctionInfo> functionInfo = StreamSupport .stream(fnIterator, false) .filter(info -> StringUtils.equals(functionName, info.getName())) .findFirst(); if(functionInfo.isPresent()) { result = success(docFormat(functionInfo.get())); } else { result = error(String.format("No docs available for function '%s'", functionName)); } return result; }  @Override String getCommand(); @Override Function<String, Boolean> getMatcher(); @Override StellarResult execute(String command, StellarShellExecutor executor); static final String DOC_PREFIX; }
@Test public void testWithFunction() { StellarResult result = command.execute("?TO_STRING", executor); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertTrue(result.getValue().toString().length() > 0); }
@Test public void testFunctionNotDefined() { StellarResult result = command.execute("?INVALID", executor); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); }
@Test public void testNoFunction() { StellarResult result = command.execute("?", executor); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); }