### Question:
PwnedPasswordChecker { public boolean check(String password) { try { return asyncCheck(password).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } } PwnedPasswordChecker(PwnedPasswordClient client); CompletableFuture<Boolean> asyncCheck(String password); boolean check(String password);  }### Answer:
@Test public void noResultsFromClientShouldNotFindPassword() { PwnedPasswordClient client = Mockito.mock(PwnedPasswordClient.class); doAnswer(invocation -> CompletableFuture.completedFuture(new ArrayList<>())) .when(client).fetchHashesAsync(any()); boolean isWeakPassword = new PwnedPasswordChecker(client).check("test"); assertFalse(isWeakPassword); }
@Test public void resultsFromClientWithoutMatchShouldNotFindPassword() { PwnedPasswordClient client = Mockito.mock(PwnedPasswordClient.class); doAnswer(invocation -> CompletableFuture.completedFuture(Arrays.asList(Hex.from("ae")))) .when(client).fetchHashesAsync(any()); boolean isWeakPassword = new PwnedPasswordChecker(client).check("test"); assertFalse(isWeakPassword); }
@Test public void resultsFromClientWithMatchShouldFindPassword() { PwnedPasswordClient client = Mockito.mock(PwnedPasswordClient.class); doAnswer(invocation -> CompletableFuture.completedFuture(Arrays.asList(Hex.from("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8")))) .when(client).fetchHashesAsync(any()); boolean isWeakPassword = new PwnedPasswordChecker(client).check("test"); assertFalse(isWeakPassword); }
@Test public void multipleHashesWithPasswordShouldFindPassword() { PwnedPasswordClient client = Mockito.mock(PwnedPasswordClient.class); doAnswer(invocation -> CompletableFuture.completedFuture(Arrays.asList(Hex.from("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8")))) .when(client).fetchHashesAsync(any()); boolean isWeakPassword = new PwnedPasswordChecker(client).check("test"); assertFalse(isWeakPassword); }