AgentStoreObserver implements StoreUpdateObserver<String, M> { @Override public void handleUpdate(String key, M oldValue, M newValue) { if (!oldValue.equals(newValue)) { List<PatchOperation> operations = agent.updatedModel(key, oldValue, newValue); if (!operations.isEmpty()) { emitter.emit(new PatchSet(key, operations)); } } }  @Override void handleNew(String key, M value); @Override void handleUpdate(String key, M oldValue, M newValue); @Override void handleRemove(String key, M oldValue);  }
@Test public void handleUpdateTest() throws Exception { given(agent.updatedModel("key", JSON_STRING_1, JSON_STRING_2)).willReturn(OPERATIONS); observer.handleUpdate("key", JSON_STRING_1, JSON_STRING_2); verify(emitter).emit(patchSet.capture()); assertThat(patchSet.getValue().getOperations(), is(OPERATIONS)); }
@Test public void handleUpdate_passes_when_models_equal() throws Exception { observer.handleUpdate("key", JSON_STRING_1, JSON_STRING_1); then(agent).shouldHaveZeroInteractions(); then(emitter).shouldHaveZeroInteractions(); }
@Test public void dontSendPatchOnUpdateEmptyOps() throws Exception { given(agent.updatedModel("key", JSON_STRING_1, JSON_STRING_2)).willReturn(Collections.emptyList()); observer.handleUpdate("key", JSON_STRING_1, JSON_STRING_2); then(emitter).shouldHaveZeroInteractions(); }