NamesResultProcessor extends ReadChildrenProcessor implements ResultProcessor { @Override protected List<ReadChildrenResult> processToModel(final String query, final ModelNode nodes) { return nodes.asList().stream() .map(node -> new ReadChildrenResult(node.asString())) .filter(result -> !isNullOrEmpty(query) && (SuggestHandler.SHOW_ALL_VALUE.equals(query) || result.name.contains(query))) .sorted(Comparator.comparing(result -> result.name)) .collect(toList()); }    }
@Test public void nullQuery() throws Exception { List<ReadChildrenResult> results = resultProcessor.processToModel(null, nodes); assertTrue(results.isEmpty()); }
@Test public void emptyQuery() throws Exception { List<ReadChildrenResult> results = resultProcessor.processToModel("", nodes); assertTrue(results.isEmpty()); }
@Test public void wildcardQuery() throws Exception { List<ReadChildrenResult> results = resultProcessor.processToModel("*", nodes); assertArrayEquals(NAMES, results.stream().map(result -> result.name).toArray(String[]::new)); }
@Test public void oneMatch() throws Exception { List<ReadChildrenResult> results = resultProcessor.processToModel("g", nodes); assertEquals(1, results.size()); assertEquals("management", results.get(0).name); }
@Test public void twoMatches() throws Exception { List<ReadChildrenResult> results = resultProcessor.processToModel("p", nodes); assertEquals(2, results.size()); assertEquals("private", results.get(0).name); assertEquals("public", results.get(1).name); }
@Test public void noMatches() throws Exception { List<ReadChildrenResult> results = resultProcessor.processToModel("foo", nodes); assertTrue(results.isEmpty()); }