### Question:
ADAMHelper extends DirectoryHelper { @Override public byte[] encodePassword(String password) { return password == null ? null : ("\"" + password + "\"").getBytes(Charset.forName("UTF-16LE")); }  @Override byte[] encodePassword(String password);  }### Answer:
@Test public void nullPasswordIsNotEncoded() { assertThat(helper.encodePassword(null)).isNull(); assertThat(helper.encodePassword(IdType.USER, (byte[][]) null)).isNull(); }
@Test public void passwordsAreOnlyEncodedForUsers() { assertThat(helper.encodePassword(IdType.AGENT, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.AGENTGROUP, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.AGENTONLY, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.FILTEREDROLE, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.GROUP, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.REALM, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.ROLE, asSet(PASSWORD))).isNull(); assertThat(helper.encodePassword(IdType.USER, asSet(PASSWORD))).isNotNull(); }
@Test public void passwordIsCorrectlyEncodedWithEnclosingDoubleQuotes() throws Exception { assertThat(helper.encodePassword(PASSWORD)).isEqualTo(("\"" + PASSWORD + "\"").getBytes(ENCODING)); }
@Test public void decodedPasswordHasDoubleQuotes() throws Exception { assertThat(new String(helper.encodePassword(PASSWORD), ENCODING)).isEqualTo(QUOTED_PASSWORD); }
@Test public void passwordSetIsCorrectlyEncoded() throws Exception { assertThat(helper.encodePassword(IdType.USER, CollectionUtils.<String>asSet())).isNull(); assertThat(helper.encodePassword(IdType.USER, asSet(PASSWORD))).isNotNull() .isEqualTo(QUOTED_PASSWORD.getBytes(ENCODING)); assertThat(helper.encodePassword(IdType.USER, asSet(PASSWORD, QUOTED_PASSWORD))).isNotNull() .isEqualTo(QUOTED_PASSWORD.getBytes(ENCODING)); }
@Test public void passwordInByteArrayIsNotModified() throws Exception { assertThat(helper.encodePassword(IdType.USER, getPasswordInByteArray(PASSWORD))).isNotNull() .isEqualTo(PASSWORD.getBytes("UTF-8")); }