TablesFunction implements Function<DataContainer> { @Override public DataContainer apply(List<Object> objects) { DataContainer dataContainer = new DataContainer(Collections.singleton(TABLE_NAME)); tablesAware.getTables() .stream() .sorted() .forEach(t -> dataContainer.addRow(Collections.singletonList(t))); return dataContainer; } @Autowired  TablesFunction(TablesAware tablesAware); @Override Class<DataContainer> getReturnType(); @Override FunctionName getName(); @Override DataContainer apply(List<Object> objects); @Override String getDescription();  }
@Test public void testApply() { DataContainer data = function.apply(Collections.emptyList()); assertThat(data.getColumnNames(), contains("table_name")); assertThat(data.getRows(), hasSize(tablesAware.getTables().size())); List<String> tableNames = data.getRows().stream() .map(dr -> String.valueOf(dr.get("table_name"))) .collect(Collectors.toList()); List<String> sortedTablesNames = new ArrayList<>(tableNames); Collections.sort(sortedTablesNames); assertThat(tableNames, equalTo(sortedTablesNames)); }