PasswordComponentImpl implements PasswordComponent { @Override public Optional<char[]> get(String dbmsName) { requireNonNull(dbmsName); final char[] value = passwords.get(dbmsName); if (value == null) { return Optional.empty(); } else { return Optional.of(value); } } PasswordComponentImpl(); @Override void put(String dbmsName, char[] password); @Override Optional<char[]> get(String dbmsName);  }
@Test void get() { assertThrows(NullPointerException.class, () -> instance.get((String) null)); assertFalse(instance.get("nonExistentDbms").isPresent()); instance.put("dbms", "password".toCharArray()); assertTrue(instance.get("dbms").isPresent()); instance.put("dbms", null); assertFalse(instance.get("dbms").isPresent()); }