### Question:
SpnegoEngine { String getCompleteServicePrincipalName(String host) { String name; if (servicePrincipalName == null) { if (useCanonicalHostname) { host = getCanonicalHostname(host); } name = "HTTP@" + host; } else { name = servicePrincipalName; if (realmName != null && !name.contains("@")) { name += "@" + realmName; } } log.debug("Service Principal Name is {}", name); return name; } SpnegoEngine(final String username,
                      final String password,
                      final String servicePrincipalName,
                      final String realmName,
                      final boolean useCanonicalHostname,
                      final Map<String, String> customLoginConfig,
                      final String loginContextName,
                      final SpnegoTokenGenerator spnegoGenerator);  SpnegoEngine(); static SpnegoEngine instance(final String username,
                                      final String password,
                                      final String servicePrincipalName,
                                      final String realmName,
                                      final boolean useCanonicalHostname,
                                      final Map<String, String> customLoginConfig,
                                      final String loginContextName); String generateToken(String host); Configuration getLoginConfiguration();  }### Answer:
@Test public void testGetCompleteServicePrincipalName() throws Exception { { SpnegoEngine spnegoEngine = new SpnegoEngine(null, null, "bob", "service.ws.apache.org", false, null, null, null); Assert.assertEquals("bob@service.ws.apache.org", spnegoEngine.getCompleteServicePrincipalName("localhost")); } { SpnegoEngine spnegoEngine = new SpnegoEngine(null, null, null, "service.ws.apache.org", true, null, null, null); Assert.assertNotEquals("HTTP@localhost", spnegoEngine.getCompleteServicePrincipalName("localhost")); Assert.assertTrue(spnegoEngine.getCompleteServicePrincipalName("localhost").startsWith("HTTP@")); } { SpnegoEngine spnegoEngine = new SpnegoEngine(null, null, null, "service.ws.apache.org", false, null, null, null); Assert.assertEquals("HTTP@localhost", spnegoEngine.getCompleteServicePrincipalName("localhost")); } }