@Test public void testHandleUserPasswordChanged() throws Exception { final UserId userId = new UserId(); final String operatingIp = "207.45.15.2"; final String password = "new password"; final String username = "buyerAbc"; final String email = "buyerAbc@163.com"; final Date time = currentTime(); final UserQueryRepository repository = mock(UserQueryRepository.class); UserEntry user = new UserEntry(); when(repository.findOne(eq(userId.toString()))).thenReturn(user); final PasswordChangedEvent event = new PasswordChangedEvent(userId, username, email, password, password, operatingIp, time); final UserListener listener = new UserListener(); listener.setUserRepository(repository); listener.handleUserPasswordChanged(event); final ArgumentCaptor<UserEntry> captor = ArgumentCaptor.forClass(UserEntry.class); verify(repository).save(captor.capture()); final UserEntry userEntry = captor.getValue(); assertThat(userEntry, notNullValue()); assertThat(userEntry.getPassword(), equalTo(password)); verify(repository).findOne(eq(userId.toString())); }
@EventHandler public void handleUserPasswordChanged(PasswordChangedEvent event) { UserEntry user = loadUser(event.getUserId(), event.getUsername()); if (user == null) { return; } user.setPassword(event.getEncodedPassword()); userRepository.save(user); logger.info("user {} password changed, id {}", event.getUsername(), event.getUserId()); }
UserListener { @EventHandler public void handleUserPasswordChanged(PasswordChangedEvent event) { UserEntry user = loadUser(event.getUserId(), event.getUsername()); if (user == null) { return; } user.setPassword(event.getEncodedPassword()); userRepository.save(user); logger.info("user {} password changed, id {}", event.getUsername(), event.getUserId()); } }
UserListener { @EventHandler public void handleUserPasswordChanged(PasswordChangedEvent event) { UserEntry user = loadUser(event.getUserId(), event.getUsername()); if (user == null) { return; } user.setPassword(event.getEncodedPassword()); userRepository.save(user); logger.info("user {} password changed, id {}", event.getUsername(), event.getUserId()); }  }
UserListener { @EventHandler public void handleUserPasswordChanged(PasswordChangedEvent event) { UserEntry user = loadUser(event.getUserId(), event.getUsername()); if (user == null) { return; } user.setPassword(event.getEncodedPassword()); userRepository.save(user); logger.info("user {} password changed, id {}", event.getUsername(), event.getUserId()); }  @EventHandler void handleUserCreated(UserCreatedEvent event); @EventHandler void handleUserPasswordChanged(PasswordChangedEvent event); @EventHandler void handleUserWithdrawPasswordCreated(WithdrawPasswordCreatedEvent event); @EventHandler void handleUserWithdrawPasswordChanged(WithdrawPasswordChangedEvent event); @EventHandler void handleUserInfoChanged(UserInfoChangedEvent event); @EventHandler void handleUserAdminInfoChanged(UserAdminInfoChangedEvent event); @EventHandler void handleUpdateNotification(NotificationSettingsUpdatedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository); }
UserListener { @EventHandler public void handleUserPasswordChanged(PasswordChangedEvent event) { UserEntry user = loadUser(event.getUserId(), event.getUsername()); if (user == null) { return; } user.setPassword(event.getEncodedPassword()); userRepository.save(user); logger.info("user {} password changed, id {}", event.getUsername(), event.getUserId()); }  @EventHandler void handleUserCreated(UserCreatedEvent event); @EventHandler void handleUserPasswordChanged(PasswordChangedEvent event); @EventHandler void handleUserWithdrawPasswordCreated(WithdrawPasswordCreatedEvent event); @EventHandler void handleUserWithdrawPasswordChanged(WithdrawPasswordChangedEvent event); @EventHandler void handleUserInfoChanged(UserInfoChangedEvent event); @EventHandler void handleUserAdminInfoChanged(UserAdminInfoChangedEvent event); @EventHandler void handleUpdateNotification(NotificationSettingsUpdatedEvent event); @SuppressWarnings("SpringJavaAutowiringInspection") @Autowired void setUserRepository(UserQueryRepository userRepository);  }