Properties { public void set(String key, String value) { String previous = this.properties.putIfAbsent(key, value); if (previous != null) throw new Error(format("property already exists, key={}, previous={}, current={}", key, previous, value)); }  void load(String classpath); Optional<String> get(String key); void set(String key, String value); Set<String> keys(); boolean containsKey(String key);  }
@Test void setWithDuplicateKey() { assertThatThrownBy(() -> { properties.set("key1", "value1"); properties.set("key1", "value2"); }).isInstanceOf(Error.class) .hasMessageContaining("key=key1, previous=value1, current=value2"); }