### Question:
TokenFetcherService { static String getPrincipalFromKeytab(String keytabLocation) { try { return Keytab .read(new File(keytabLocation)) .getEntries().get(0) .getPrincipalName() .split("@")[0] .replace('\\', '/'); } catch (Exception ex) { throw new TokenServiceException(ex.getMessage(), ErrorCode.READ_KEYTAB_EXCEPTION); } } private  TokenFetcherService(final Configuration conf); static TokenFetcherService getInstance(Configuration conf); String getDelegationTokens(Map<String, String[]> params); static final List<String> SUPPORTED_TOKEN_KINDS; }### Answer:
@Test public void testGetPrincipalFromKeytab() throws IOException { String keytabLocation = "dummy.keytab"; String expectedPrincipalName = "somedomain/somehost"; String fullPrincipalName = expectedPrincipalName + "@somecompany.com"; Keytab kt = new Keytab(); KeytabEntry kte = new KeytabEntry(fullPrincipalName, 0, new KerberosTime(), (byte) (0), new EncryptionKey(EncryptionType.AES256_CTS_HMAC_SHA1_96, new byte[0])); kt.setEntries(Arrays.asList(kte)); File keytabFile = new File(keytabLocation); kt.write(keytabFile); String actualPrincipalName = TokenFetcherService.getPrincipalFromKeytab(keytabLocation); Assert.assertEquals(actualPrincipalName, expectedPrincipalName); keytabFile.delete(); }