### Question:
TaskManagerLocation implements Comparable<TaskManagerLocation>, java.io.Serializable { public String getHostname() { return hostName; } TaskManagerLocation(ResourceID resourceID, InetAddress inetAddress, int dataPort); ResourceID getResourceID(); int dataPort(); InetAddress address(); String addressString(); String getFQDNHostname(); String getHostname(); static String getHostName(InetAddress inetAddress); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(@Nonnull TaskManagerLocation o);  }### Answer:
@Test public void testGetHostname0() { try { InetAddress address = mock(InetAddress.class); when(address.getCanonicalHostName()).thenReturn("worker2.cluster.mycompany.com"); when(address.getHostName()).thenReturn("worker2.cluster.mycompany.com"); when(address.getHostAddress()).thenReturn("127.0.0.1"); final TaskManagerLocation info = new TaskManagerLocation(ResourceID.generate(), address, 19871); Assert.assertEquals("worker2", info.getHostname()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testGetHostname1() { try { InetAddress address = mock(InetAddress.class); when(address.getCanonicalHostName()).thenReturn("worker10"); when(address.getHostName()).thenReturn("worker10"); when(address.getHostAddress()).thenReturn("127.0.0.1"); TaskManagerLocation info = new TaskManagerLocation(ResourceID.generate(), address, 19871); Assert.assertEquals("worker10", info.getHostname()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }