MDPasswordEncoder implements IPasswordEncoder { @Override public String encode(@Nonnull final String password) throws EncodingException { try { MessageDigest messageDigest = getMessageDigest(); byte[] digest = messageDigest.digest(charSequenceCodec.encode(password)); for (int i = 1; i < iterations; i++) { digest = messageDigest.digest(digest); } return charSequenceCodec.decode(encoder.encode(digest)); } catch (Exception e) { throw new EncodingException("Password encoding has been failed because: " + e.getMessage(), e); } } private  MDPasswordEncoder(
            final String algorithm,
            final IEncoder encoder,
            final ICharSequenceCodec charSequenceCodec
    ); static MDPasswordEncoder create(
            @Nonnull final String algorithm,
            @Nonnull final IEncoder encoder,
            @Nonnull final ICharSequenceCodec charSequenceCodec
    ); @Override String encode(@Nonnull final String password); @Override String encode(@Nonnull final String password, @Nonnull final String salt); @Override void setIterations(final int iterations);  }
@Test public void encodePasswordTest() throws EncodingException, DecodingException { resetVerifyMockObject(); String result = passwordEncoder.encode(password); assertNotEquals(result, null); assertEquals(result, charSequenceEncodePassword); verify(encoder, times(1)).encode(anyObject()); verify(charSequenceCodec, times(1)).encode(password); verify(charSequenceCodec).decode(eq(encodePassword.getBytes())); }
@Test public void encodePasswordWithSaltTest() throws EncodingException, DecodingException { resetVerifyMockObject(); final String salt = "testSalt"; String result = passwordEncoder.encode(password, salt); assertNotEquals(result, null); assertEquals(result, charSequenceEncodePassword); verify(encoder, times(1)).encode(anyObject()); verify(charSequenceCodec, times(1)).encode(password + "{" + salt + "}"); verify(charSequenceCodec).decode(eq(encodePassword.getBytes())); }