### Question:
MapperUtils { public static String buildPrincipalName(String principal, @Nullable String userPrefix, @Nullable String userDomain) { boolean userDomainIncluded = StringUtils.substringAfterLast(principal, "@").equals(userDomain); if (StringUtils.isNotBlank(userPrefix) && !StringUtils.startsWith(principal, userPrefix)) { principal = String.format("%s.%s", userPrefix, principal); if (userDomainIncluded) { String userIdDomainTruncated = StringUtils.substringBeforeLast(principal, "@"); principal = StringUtils.left(userIdDomainTruncated, 20); principal = String.format("%s@%s", principal, userDomain); } else { principal = StringUtils.left(principal, 20); } } if (StringUtils.isNotBlank(userDomain) && !userDomainIncluded) { principal = String.format("%s@%s", principal, userDomain); } return principal; }  static Function<String, String> getRdnMappingFunction(final String key); static Stream<String> mapAttributes(String[] elements, Function<String, String> mapper); static String getAttribute(DirContextAdapter adapter, String... names); static String stripBaseFromDn(String dn, String base); static String appendToDn(String dn, String... suffixes); static String buildGroupName(String name, String domain); static String buildGroupName(String name, AcmLdapSyncConfig ldapSyncConfig); static String buildUserId(String userId, String domain); static String buildUserId(String userId, AcmLdapSyncConfig ldapSyncConfig); static byte[] encodeUTF16LE(String str); static String generatePassword(int minLength); static String buildPrincipalName(String principal, @Nullable String userPrefix, @Nullable String userDomain); static final Function<DirContextAdapter, LocalDate> convertFileTimeTimestampToDate; static final Function<DirContextAdapter, LocalDate> calculatePasswordExpirationDateByShadowAccount; static final Function<String, BasicAttribute> openLdapPasswordToAttribute; static final Function<String, BasicAttribute> openLdapCurrentPasswordToAttribute; static final Function<String, BasicAttribute> activeDirectoryPasswordToAttribute; }### Answer:
@Test public void testPrincipalPrefixAndDomainIncluded() { String principal = "100.ann-acm@armedia.com"; String result = MapperUtils.buildPrincipalName(principal, "100", "armedia.com"); assertEquals(principal, result); }
@Test public void testPrincipalPrefixIncluded() { String principal = "100.ann-acm"; String result = MapperUtils.buildPrincipalName(principal, "100", "armedia.com"); assertEquals("100.ann-acm@armedia.com", result); }
@Test public void testLongPrincipalPrefixNotIncludedShouldTruncateTo20Chars() { String principal = "ann-acmloooooooooong"; String result = MapperUtils.buildPrincipalName(principal, "100", "armedia.com"); assertEquals("100.ann-acmloooooooo@armedia.com", result); }
@Test public void testLongPrincipalPrefixNotIncludedDomainIncluded() { String principal = "ann-acmloooooooooong@armedia.com"; String result = MapperUtils.buildPrincipalName(principal, "100", "armedia.com"); assertEquals("100.ann-acmloooooooo@armedia.com", result); }