### Question:
MultipleAddresses { public InetSocketAddress getReachableOrOne() { InetSocketAddress address; if (addresses.size() == 1) { return getOne(); } try { address = getReachableAddress(); } catch (NoRouteToHostException e) { address = getOne(); } return address; } 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 testGetReachableOrOneWithSingleReachableAddress() { InetSocketAddress reachableAddress = new InetSocketAddress("127.0.0.1", PortAssignment.unique()); MultipleAddresses multipleAddresses = new MultipleAddresses(Collections.singletonList(reachableAddress)); InetSocketAddress actualReturnedAddress = multipleAddresses.getReachableOrOne(); assertEquals(reachableAddress, actualReturnedAddress); }
@Test public void testGetReachableOrOneWithSingleUnreachableAddress() { InetSocketAddress unreachableAddress = new InetSocketAddress("unreachable.address.zookeeper.apache.com", 1234); MultipleAddresses multipleAddresses = new MultipleAddresses(Collections.singletonList(unreachableAddress)); InetSocketAddress actualReturnedAddress = multipleAddresses.getReachableOrOne(); assertEquals(unreachableAddress, actualReturnedAddress); }