/**
   * Check null or empty mappings.
   *
   * @param map Mappings.
   * @throws Exception If failed.
   */
  private void checkNullOrEmptyMappings(@Nullable Map<String, String> map) throws Exception {
    BasicUserNameMapper mapper = create(map, false, null);

    assertNull(mapper.map(null));
    assertEquals("1", mapper.map("1"));
    assertEquals("2", mapper.map("2"));

    mapper = create(map, true, null);

    assertNull(mapper.map(null));
    assertNull(mapper.map("1"));
    assertNull(mapper.map("2"));

    mapper = create(map, false, "A");

    assertNull(mapper.map(null));
    assertEquals("1", mapper.map("1"));
    assertEquals("2", mapper.map("2"));

    mapper = create(map, true, "A");

    assertEquals("A", mapper.map(null));
    assertEquals("A", mapper.map("1"));
    assertEquals("A", mapper.map("2"));
  }
  /**
   * Create mapper.
   *
   * @param dictionary Dictionary.
   * @param useDfltUsrName Whether to use default user name.
   * @param dfltUsrName Default user name.
   * @return Mapper.
   */
  private BasicUserNameMapper create(
      @Nullable Map<String, String> dictionary,
      boolean useDfltUsrName,
      @Nullable String dfltUsrName) {
    BasicUserNameMapper mapper = new BasicUserNameMapper();

    mapper.setMappings(dictionary);
    mapper.setUseDefaultUserName(useDfltUsrName);
    mapper.setDefaultUserName(dfltUsrName);

    return mapper;
  }
  /**
   * Test regular mappings.
   *
   * @throws Exception If failed.
   */
  public void testMappings() throws Exception {
    Map<String, String> map = new HashMap<>();

    map.put("1", "101");

    BasicUserNameMapper mapper = create(map, false, null);

    assertNull(mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertEquals("2", mapper.map("2"));

    mapper = create(map, true, null);

    assertNull(mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertNull(mapper.map("2"));

    mapper = create(map, false, "A");

    assertNull(mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertEquals("2", mapper.map("2"));

    mapper = create(map, true, "A");

    assertEquals("A", mapper.map(null));
    assertEquals("101", mapper.map("1"));
    assertEquals("A", mapper.map("2"));
  }