### Question:
PasswordSecurity implements Reloadable { public boolean comparePassword(String password, String playerName) { HashedPassword auth = dataSource.getPassword(playerName); return auth != null && comparePassword(password, auth, playerName); } PasswordSecurity(Map<String, HashedPassword> storage, EncryptionMethod encryptionMethod); @PostConstruct @Override void reload(); HashedPassword computeHash(String password, String playerName); boolean comparePassword(String password, String playerName); boolean comparePassword(String password, HashedPassword hashedPassword, String playerName);  }### Answer:
@Test public void shouldReturnPasswordMatch() { HashedPassword password = new HashedPassword("$TEST$10$SOME_HASH", null); String playerName = "Tester"; String playerLowerCase = playerName.toLowerCase(); String clearTextPass = "myPassTest"; given(dataSource.getPassword(playerName)).willReturn(password); given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(true); boolean result = passwordSecurity.comparePassword(clearTextPass, playerName); assertThat(result, equalTo(true)); verify(dataSource).getPassword(playerName); verify(pluginManager).callEvent(any(PasswordEncryptionEvent.class)); verify(method).comparePassword(clearTextPass, password, playerLowerCase); }
@Test public void shouldReturnPasswordMismatch() { HashedPassword password = new HashedPassword("$TEST$10$SOME_HASH", null); String playerName = "My_PLayer"; String playerLowerCase = playerName.toLowerCase(); String clearTextPass = "passw0Rd1"; given(dataSource.getPassword(playerName)).willReturn(password); given(method.comparePassword(clearTextPass, password, playerLowerCase)).willReturn(false); boolean result = passwordSecurity.comparePassword(clearTextPass, playerName); assertThat(result, equalTo(false)); verify(dataSource).getPassword(playerName); verify(pluginManager).callEvent(any(PasswordEncryptionEvent.class)); verify(method).comparePassword(clearTextPass, password, playerLowerCase); }
@Test public void shouldReturnFalseIfPlayerDoesNotExist() { String playerName = "bobby"; String clearTextPass = "tables"; given(dataSource.getPassword(playerName)).willReturn(null); boolean result = passwordSecurity.comparePassword(clearTextPass, playerName); assertThat(result, equalTo(false)); verify(dataSource).getPassword(playerName); verify(method, never()).comparePassword(anyString(), any(HashedPassword.class), anyString()); }