@Test
public void testValidateHostname() {

    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(hostnameResolver.getAllByName("abc.athenz.com"))
           .thenReturn(new HashSet<String>(Arrays.asList("10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1")));
    InstanceZTSProvider provider = new InstanceZTSProvider();
    provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceZTSProvider", null, null);
    provider.setHostnameResolver(hostnameResolver);
    assertTrue(provider.validateHostname("abc.athenz.com", new String[]{"10.1.1.1"}));
    assertTrue(provider.validateHostname("abc.athenz.com", new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}));
    assertFalse(provider.validateHostname("abc.athenz.com", new String[]{"10.1.1.2"}));
    assertFalse(provider.validateHostname("abc.athenz.com", new String[]{"10.1.1.1", "1:2:3:4:5:6:7:8"}));
    assertFalse(provider.validateHostname("abc.athenz.com", new String[]{"10.1.1.2", "1:2:3:4:5:6:7:8"}));
    // If hostname is passed, sanIp must be non empty
    assertFalse(provider.validateHostname("abc.athenz.com", null));
    assertFalse(provider.validateHostname("abc.athenz.com", new String[]{}));
    assertFalse(provider.validateHostname("abc.athenz.com", new String[]{""}));
    // It's possible client didn't set Hostname payload. One sanIp be optionally set, and would have been matched with clientIp upstream
    assertTrue(provider.validateHostname("", new String[]{"10.1.1.1"}));
    assertTrue(provider.validateHostname(null, new String[]{"10.1.1.1"}));
    // If more than one sanIp is passed, hostname must be non empty
    assertFalse(provider.validateHostname(null, new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}));
    assertFalse(provider.validateHostname("", new String[]{"10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1"}));
    provider.close();
}