@Test public void testGetServerPrincipal() throws IOException { String service = "TestKerberosUtil"; String localHostname = KerberosUtil.getLocalHostName(); String testHost = "FooBar"; // send null hostname Assert.assertEquals( "When no hostname is sent", service + "/" + localHostname.toLowerCase(Locale.ENGLISH), KerberosUtil.getServicePrincipal(service, null)); // send empty hostname Assert.assertEquals( "When empty hostname is sent", service + "/" + localHostname.toLowerCase(Locale.ENGLISH), KerberosUtil.getServicePrincipal(service, "")); // send 0.0.0.0 hostname Assert.assertEquals( "When 0.0.0.0 hostname is sent", service + "/" + localHostname.toLowerCase(Locale.ENGLISH), KerberosUtil.getServicePrincipal(service, "0.0.0.0")); // send uppercase hostname Assert.assertEquals( "When uppercase hostname is sent", service + "/" + testHost.toLowerCase(Locale.ENGLISH), KerberosUtil.getServicePrincipal(service, testHost)); // send lowercase hostname Assert.assertEquals( "When lowercase hostname is sent", service + "/" + testHost.toLowerCase(Locale.ENGLISH), KerberosUtil.getServicePrincipal(service, testHost.toLowerCase(Locale.ENGLISH))); }