### Question:
MultipleAddresses { public Set<InetSocketAddress> getAllReachableAddressesOrAll() { if (addresses.size() == 1) { return getAllAddresses(); } Set<InetSocketAddress> allReachable = getAllReachableAddresses(); if (allReachable.isEmpty()) { return getAllAddresses(); } return allReachable; } MultipleAddresses();  MultipleAddresses(Collection<InetSocketAddress> addresses);  MultipleAddresses(InetSocketAddress address);  MultipleAddresses(Collection<InetSocketAddress> addresses, Duration timeout); boolean isEmpty(); Set<InetSocketAddress> getAllAddresses(); Set<InetSocketAddress> getWildcardAddresses(); List<Integer> getAllPorts(); List<String> getAllHostStrings(); void addAddress(InetSocketAddress address); InetSocketAddress getReachableAddress(); Set<InetSocketAddress> getAllReachableAddresses(); Set<InetSocketAddress> getAllReachableAddressesOrAll(); InetSocketAddress getReachableOrOne(); void recreateSocketAddresses(); InetSocketAddress getOne(); int size(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final Duration DEFAULT_TIMEOUT; }### Answer:
@Test public void testGetAllReachableAddressesOrAllWhenSomeReachable() throws Exception { InetSocketAddress reachableHost1 = new InetSocketAddress("127.0.0.1", 1234); InetSocketAddress reachableHost2 = new InetSocketAddress("127.0.0.1", 2345); InetSocketAddress unreachableHost1 = new InetSocketAddress("unreachable1.address.zookeeper.apache.com", 1234); InetSocketAddress unreachableHost2 = new InetSocketAddress("unreachable2.address.zookeeper.apache.com", 1234); MultipleAddresses multipleAddresses = new MultipleAddresses( Arrays.asList(unreachableHost1, unreachableHost2, reachableHost1, reachableHost2)); Set<InetSocketAddress> reachableHosts = new HashSet<>(Arrays.asList(reachableHost1, reachableHost2)); assertEquals(reachableHosts, multipleAddresses.getAllReachableAddressesOrAll()); }
@Test public void testGetAllReachableAddressesOrAllWhenNoneReachable() throws Exception { InetSocketAddress unreachableHost1 = new InetSocketAddress("unreachable1.address.zookeeper.apache.com", 1234); InetSocketAddress unreachableHost2 = new InetSocketAddress("unreachable2.address.zookeeper.apache.com", 1234); InetSocketAddress unreachableHost3 = new InetSocketAddress("unreachable3.address.zookeeper.apache.com", 1234); List<InetSocketAddress> allUnreachableAddresses = Arrays.asList(unreachableHost1, unreachableHost2, unreachableHost3); MultipleAddresses multipleAddresses = new MultipleAddresses(allUnreachableAddresses); assertEquals(new HashSet<>(allUnreachableAddresses), multipleAddresses.getAllReachableAddressesOrAll()); }