### Question:
UserCommandHandler { @CommandHandler public void handleChangeWithdrawPasswordCommand(ChangeWithdrawPasswordCommand command) { notNull(command.getUserId()); hasLength(command.getConfirmedWithdrawPassword()); hasLength(command.getWithdrawPassword()); isTrue(command.isValid(), "The password and confirmed password should be the same, but password should be different from previous one!"); User user = repository.load(command.getUserId()); if (user == null) { logger.warn("cannot find user {}", command.getUserId()); return; } final String withdrawPassword = user.getWithdrawPassword(); final boolean matches = passwordEncoder.matches(command.getPreviousWithdrawPassword(), withdrawPassword); if (matches) { logger.warn("user {}, id {}, withdraw password not matched for previous to change.", command.getUsername(), command.getUserId()); return; } final Date changedTime = nullSafe(command.getChangedTime(), currentTime()); user.changeWithdrawPassword(passwordEncoder.encode(command.getWithdrawPassword()), passwordEncoder.encode(command.getConfirmedWithdrawPassword()), command.getOperatingIp(), changedTime); logger.info("userid {}, username {} has changed withdraw password!", command.getUserId(), command.getUsername()); }  @CommandHandler UserId handleCreateUser(CreateUserCommand command); @CommandHandler UserAccount handleAuthenticateUser(AuthenticateUserCommand command); @CommandHandler String handleForgetPassword(ForgetPasswordCommand command); @CommandHandler String handlePasswordReset(ResetPasswordCommand command); @CommandHandler void handleChangePassword(ChangePasswordCommand command); @CommandHandler void handleChangeWithdrawPasswordCommand(ChangeWithdrawPasswordCommand command); @CommandHandler void handleCreateWithdrawPasswordCommand(CreateWithdrawPasswordCommand command); @CommandHandler void handleUpdateNotificationCommand(UpdateNotificationSettingsCommand command); @CommandHandler void handleChangeInfoCommand(ChangeInfoCommand command); @CommandHandler void handleChangeAdminInfoCommand(ChangeAdminInfoCommand command); @Autowired @Qualifier("userRepository") void setRepository(Repository<User> userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordEncoder(PasswordEncoder passwordEncoder); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserPasswordResetRepository(UserPasswordResetRepository userPasswordResetRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setPasswordResetTokenGenerator(PasswordResetTokenGenerator passwordResetTokenGenerator); static List<String> DEFAULT_ROLES; }### Answer:
@Test public void testHandleChangeWithdrawPasswordCommand() throws Exception { UserId aggregateIdentifier = new UserId(); final Date time = currentTime(); final String operatingIp = "223.124.18.123"; final Identifier identifier = new Identifier(Identifier.Type.IDENTITY_CARD, "110101201101019252"); Date changedTime = currentTime(); UserEntry userEntry = new UserEntry(); userEntry.setUsername("buyer1"); userEntry.setPrimaryKey(aggregateIdentifier.toString()); userEntry.setLastName("Buyer One"); userEntry.setFirstName("Mr"); userEntry.setIdentifier(identifier); when(userQueryRepository.findByUsername("buyer1")).thenReturn(userEntry); String newPassword = passwordEncoder.encode("newPassword"); ChangeWithdrawPasswordCommand command = new ChangeWithdrawPasswordCommand(aggregateIdentifier, "buyer1", passwordEncoder.encode("buyer1"), newPassword, newPassword, operatingIp, changedTime); fixture.given(new UserCreatedEvent(aggregateIdentifier, "buyer1", "Mr", "Buyer One", identifier, "buyer1@163.com", passwordEncoder.encode("buyer1"), UserCommandHandler.DEFAULT_ROLES, time)) .when(command) .expectEventsMatching( Matchers.payloadsMatching( sequenceOf(new PasswordChangedEventMatcher<WithdrawPasswordChangedEvent>( new WithdrawPasswordChangedEvent(aggregateIdentifier, "buyer1", "buyer1@163.com", passwordEncoder.encode("buyer1"), passwordEncoder.encode("buyer1"), operatingIp, changedTime), passwordEncoder, "buyer1")))); }