AbstractBalancer implements Balancer<Z, D> { @Override public Iterable<D> backups() { Iterator<D> databases = this.getDatabases().iterator(); if (!databases.hasNext() || ((databases.next() != null) && !databases.hasNext())) return Collections.emptySet(); D database = databases.next(); if (!databases.hasNext()) return Collections.singleton(database); SortedSet<D> backups = new TreeSet<>(); backups.add(database); do { backups.add(databases.next()); } while (databases.hasNext()); return backups; }  @Override Iterable<D> backups(); @Override Iterator<D> iterator(); @Override boolean contains(Object database); @Override boolean containsAll(Collection<?> databases); @Override boolean isEmpty(); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] array); @Override boolean equals(Object object); @Override int hashCode(); @Override String toString();  }
@Test public void backups() { Balancer<Void, MockDatabase> balancer = this.factory.createBalancer(Collections.<MockDatabase>emptySet()); Iterable<MockDatabase> result = balancer.backups(); assertNotNull(result); Iterator<MockDatabase> backups = result.iterator(); assertFalse(backups.hasNext()); balancer = this.factory.createBalancer(Collections.singleton(this.databases[0])); result = balancer.backups(); assertNotNull(result); backups = result.iterator(); assertFalse(backups.hasNext()); balancer = this.factory.createBalancer(new HashSet<>(Arrays.asList(this.databases[0], this.databases[1]))); result = balancer.backups(); assertNotNull(result); backups = result.iterator(); assertTrue(backups.hasNext()); assertSame(this.databases[1], backups.next()); assertFalse(backups.hasNext()); balancer = this.factory.createBalancer(new HashSet<>(Arrays.asList(this.databases))); result = balancer.backups(); assertNotNull(result); backups = result.iterator(); assertTrue(backups.hasNext()); assertSame(this.databases[1], backups.next()); assertTrue(backups.hasNext()); assertSame(this.databases[2], backups.next()); assertFalse(backups.hasNext()); }