/**
  * Test that an iterator created with the specified prefix on a service with the specified names,
  * which should result in an iteration that returns two names, responds properly to the remove
  * method.
  */
 private void testRemoveTwoElements(String prefix, String... names) {
   List<String> list = Arrays.asList(names);
   service.clear();
   service.addAll(list);
   List<String> matchingNames = new ArrayList<String>();
   for (String name : BoundNamesUtil.getServiceBoundNamesIterable(service, prefix)) {
     matchingNames.add(name);
   }
   Iterator<String> iter = BoundNamesUtil.getServiceBoundNamesIterator(service, prefix);
   assertRemoveFails(iter);
   /* Remove first */
   iter.next();
   iter.remove();
   assertRemoveFails(iter);
   assertContents(
       BoundNamesUtil.getServiceBoundNamesIterator(service, prefix), matchingNames.get(1));
   /* Also remove second */
   iter.next();
   iter.remove();
   assertRemoveFails(iter);
   assertContents(BoundNamesUtil.getServiceBoundNamesIterator(service, prefix));
   service.clear();
   service.addAll(list);
   iter = BoundNamesUtil.getServiceBoundNamesIterator(service, prefix);
   /* Just remove second */
   iter.next();
   iter.next();
   assertNextFails(iter);
   iter.remove();
   assertRemoveFails(iter);
   assertContents(
       BoundNamesUtil.getServiceBoundNamesIterator(service, prefix), matchingNames.get(0));
 }
 /**
  * Test that an iterator created with the specified prefix on a service with the specified names,
  * which should result in an iteration that returns no names, responds properly to the remove
  * method.
  */
 private void testRemoveEmpty(String prefix, String... names) {
   List<String> list = Arrays.asList(names);
   service.clear();
   service.addAll(list);
   Iterator<String> iter = BoundNamesUtil.getServiceBoundNamesIterator(service, prefix);
   assertRemoveFails(iter);
   assertNextFails(iter);
   assertRemoveFails(iter);
 }
 /**
  * Test that an iterator created with the specified prefix on a service with the specified names,
  * which should result in an iteration that returns one name, responds properly to the remove
  * method.
  */
 private void testRemoveOneElement(String prefix, String... names) {
   List<String> list = Arrays.asList(names);
   service.clear();
   service.addAll(list);
   Iterator<String> iter = BoundNamesUtil.getServiceBoundNamesIterator(service, prefix);
   assertRemoveFails(iter);
   iter.next();
   assertNextFails(iter);
   iter.remove();
   assertRemoveFails(iter);
   assertNextFails(iter);
   assertContents(BoundNamesUtil.getServiceBoundNamesIterator(service, prefix));
 }
 /** Tests iterations that return names. */
 private void testMatch(CheckIterator check) {
   service.addAll(
       Arrays.asList("able", "al", "alan", "alex", "ann", "bill", "billy", "bob", "bobby"));
   check.checkContents("", "able", "al", "alan", "alex", "ann", "bill", "billy", "bob", "bobby");
   check.checkContents("a", "able", "al", "alan", "alex", "ann");
   check.checkContents("al", "alan", "alex");
   check.checkContents("ale", "alex");
   check.checkContents("alex");
   check.checkContents("b", "bill", "billy", "bob", "bobby");
   check.checkContents("bill", "billy");
   check.checkContents("billy");
 }
 /** Tests iterations that return no names. */
 private void testNoMatch(CheckIterator check) {
   check.checkContents("");
   service.addAll(Arrays.asList("bill", "bob"));
   check.checkContents("a");
   check.checkContents("ba");
   check.checkContents("billy");
   check.checkContents("bit");
   check.checkContents("boa");
   check.checkContents("bob");
   check.checkContents("bobby");
   check.checkContents("carl");
 }