SessionImpl implements Session { @Override public void set(String key, String value) { String previousValue = values.put(key, value); if (!Strings.equals(previousValue, value)) { changedFields.add(key); } } SessionImpl(String domain); @Override Optional<String> get(String key); @Override void set(String key, String value); @Override void invalidate();  }
@Test void set() { session.set("key", "value"); assertThat(session.changedFields).containsOnly("key"); assertThat(session.get("key")).get().isEqualTo("value"); session.set("key", null); assertThat(session.changedFields).containsOnly("key"); assertThat(session.get("key")).isNotPresent(); }
@Test void setWithoutChange() { session.set("key", null); assertThat(session.changedFields).isEmpty(); session.values.put("key", "value"); session.set("key", "value"); assertThat(session.changedFields).isEmpty(); }