@Test public void testResolveToHostNameShouldReturnUnknownHostNameWhenUnknownHostExceptionOccurs() throws UnknownHostException { String expectedHostName = "UNKNOWN HOST(anIPAddress)"; given(inetAddressFactory.createByName("anIPAddress")).willThrow(new UnknownHostException()); String actualHostName = underTest.resolveToHostName("anIPAddress"); assertEquals(expectedHostName, actualHostName); }
public String resolveToHostName(final String ip) { String host = ""; try { InetAddress address = inetAddressFactory.createByName(ip); host = address.getHostName(); } catch (UnknownHostException e) { logger.debug(DEBUG_MESSAGE + host, e); host = String.format(UNKNOWN_HOST_TEMPLATE, ip); } return host; }
IpAddressResolver { public String resolveToHostName(final String ip) { String host = ""; try { InetAddress address = inetAddressFactory.createByName(ip); host = address.getHostName(); } catch (UnknownHostException e) { logger.debug(DEBUG_MESSAGE + host, e); host = String.format(UNKNOWN_HOST_TEMPLATE, ip); } return host; } }
IpAddressResolver { public String resolveToHostName(final String ip) { String host = ""; try { InetAddress address = inetAddressFactory.createByName(ip); host = address.getHostName(); } catch (UnknownHostException e) { logger.debug(DEBUG_MESSAGE + host, e); host = String.format(UNKNOWN_HOST_TEMPLATE, ip); } return host; }  }
IpAddressResolver { public String resolveToHostName(final String ip) { String host = ""; try { InetAddress address = inetAddressFactory.createByName(ip); host = address.getHostName(); } catch (UnknownHostException e) { logger.debug(DEBUG_MESSAGE + host, e); host = String.format(UNKNOWN_HOST_TEMPLATE, ip); } return host; }  String resolveToHostName(final String ip); }
IpAddressResolver { public String resolveToHostName(final String ip) { String host = ""; try { InetAddress address = inetAddressFactory.createByName(ip); host = address.getHostName(); } catch (UnknownHostException e) { logger.debug(DEBUG_MESSAGE + host, e); host = String.format(UNKNOWN_HOST_TEMPLATE, ip); } return host; }  String resolveToHostName(final String ip);  }