UuidCompleter implements Completer { @Override public int complete(String buffer, int cursor, List<String> candidates) { String query = (buffer == null) ? ".*" : buffer; if (!query.contains("*")) { query = query.concat(".*"); } StringsCompleter delegate = new StringsCompleter(); for (Intent intent : provider.listIntents(true)) { String id = intent.getId().getValue(); if (id.matches(query)) { candidates.add(id); delegate.getStrings().add(id); } } return delegate.complete(buffer, cursor, candidates); } UuidCompleter(NicConsoleProvider provider); @Override int complete(String buffer, int cursor, List<String> candidates);  }
@Test public final void testComplete() throws Exception { final int success = 0; final int failure = -1; final int cursor = 1; final String validId = UUID.randomUUID().toString(); final String invalidId = "c20bec-c874-4f31-bf9e-a88e56b05"; final String invalidUUID = "Invalid uuid"; final List<String> candidateList = new ArrayList<String>(); final List<Intent> intentList = new ArrayList<Intent>(); intentList.add(intent); when(provider.listIntents(true)).thenReturn(intentList); when(intent.getId()).thenReturn(uuid); when(uuid.getValue()).thenReturn(validId); assertEquals(invalidUUID, failure, uuidCompleter.complete(invalidId, cursor, candidateList)); assertEquals(success, uuidCompleter.complete(validId, cursor, candidateList)); assertEquals(success, uuidCompleter.complete(null, cursor, candidateList)); assertEquals(success, uuidCompleter.complete("", cursor, candidateList)); }