### Question:
HostStatesImpl implements HostStates, Closeable { @Override public boolean isUp(InetAddress address) { refreshNodeStatus(); Boolean status = myHostStates.get(address); return status != null && status; } private  HostStatesImpl(Builder builder); @Override boolean isUp(InetAddress address); @Override boolean isUp(Host host); @Override void close(); static Builder builder();  }### Answer:
@Test public void testIsInetAddressUp() throws UnknownHostException { InetAddress expectedAddress = InetAddress.getLocalHost(); List<String> expectedLiveNodes = Collections.singletonList(expectedAddress.getHostName()); List<String> expectedUnreachableNodes = Collections.emptyList(); when(myJmxProxy.getLiveNodes()).thenReturn(expectedLiveNodes); when(myJmxProxy.getUnreachableNodes()).thenReturn(expectedUnreachableNodes); assertThat(myHostStates.isUp(expectedAddress)).isTrue(); }
@Test public void testIsHostUp() throws UnknownHostException { InetAddress expectedAddress = InetAddress.getLocalHost(); Host expectedHost = mock(Host.class); List<String> expectedLiveNodes = Collections.singletonList(expectedAddress.getHostName()); List<String> expectedUnreachableNodes = Collections.emptyList(); when(myJmxProxy.getLiveNodes()).thenReturn(expectedLiveNodes); when(myJmxProxy.getUnreachableNodes()).thenReturn(expectedUnreachableNodes); when(expectedHost.getBroadcastAddress()).thenReturn(expectedAddress); assertThat(myHostStates.isUp(expectedHost)).isTrue(); }
@Test public void testIsInetAddressUpFaultyNode() throws UnknownHostException { InetAddress expectedAddress = InetAddress.getLocalHost(); when(myJmxProxy.getLiveNodes()).thenReturn(Collections.emptyList()); when(myJmxProxy.getUnreachableNodes()).thenReturn(Collections.emptyList()); assertThat(myHostStates.isUp(expectedAddress)).isFalse(); }
@Test public void testNodeIsNotRefreshed() throws UnknownHostException { final InetAddress expectedAddress = InetAddress.getLocalHost(); when(myJmxProxy.getLiveNodes()).thenAnswer(new Answer<List<String>>() { private int counter = 0; @Override public List<String> answer(InvocationOnMock invocation) { if (counter++ == 2) { return Collections.singletonList(expectedAddress.getHostAddress()); } return Collections.emptyList(); } }); when(myJmxProxy.getUnreachableNodes()).thenAnswer(new Answer<List<String>>() { private int counter = 0; @Override public List<String> answer(InvocationOnMock invocation) { if (counter++ == 2) { return Collections.emptyList(); } return Collections.singletonList(expectedAddress.getHostAddress()); } }); assertThat(myHostStates.isUp(expectedAddress)).isFalse(); assertThat(myHostStates.isUp(expectedAddress)).isFalse(); }