### Question:
DefaultDataDomainFlushAction implements DataDomainFlushAction { protected List<DbRowOp> mergeSameObjectIds(List<DbRowOp> dbRowOps) { Map<ObjectId, DbRowOp> index = new HashMap<>(dbRowOps.size()); dbRowOps.forEach(row -> index.merge(row.getChangeId(), row, DbRowOpMerger.INSTANCE)); dbRowOps.clear(); dbRowOps.addAll(index.values()); return dbRowOps; } protected  DefaultDataDomainFlushAction(DataDomain dataDomain, DbRowOpSorter dbRowOpSorter, JdbcEventLogger jdbcEventLogger); @Override GraphDiff flush(DataContext context, GraphDiff changes);  }### Answer:
@Test public void mergeSameObjectIds() { ObjectId id1 = ObjectId.of("test2", "id", 1); ObjectId id2 = ObjectId.of("test", "id", 2); ObjectId id3 = ObjectId.of("test", "id", 2); ObjectId id4 = ObjectId.of("test", "id", 3); ObjectId id5 = ObjectId.of("test2", "id", 4); ObjectId id6 = ObjectId.of("test", "id", 5); ObjectId id7 = ObjectId.of("test", "id", 6); ObjectId id8 = ObjectId.of("test2", "id", 3); ObjectId id9 = ObjectId.of("test2", "id", 4); ObjectId id10 = ObjectId.of("test", "id", 6); DbEntity test = mockEntity("test"); DbEntity test2 = mockEntity("test2"); BaseDbRowOp[] op = new BaseDbRowOp[10]; op[0] = new InsertDbRowOp(mockObject(id1), test2, id1); op[1] = new InsertDbRowOp(mockObject(id2), test, id2); op[2] = new DeleteDbRowOp(mockObject(id3), test, id3); op[3] = new UpdateDbRowOp(mockObject(id4), test, id4); op[4] = new InsertDbRowOp(mockObject(id5), test2, id5); op[5] = new DeleteDbRowOp(mockObject(id6), test, id6); op[6] = new InsertDbRowOp(mockObject(id7), test, id7); op[7] = new UpdateDbRowOp(mockObject(id8), test2, id8); op[8] = new DeleteDbRowOp(mockObject(id9), test2, id9); op[9] = new DeleteDbRowOp(mockObject(id10), test, id10); DefaultDataDomainFlushAction action = mock(DefaultDataDomainFlushAction.class); when(action.mergeSameObjectIds((List<DbRowOp>) any(List.class))).thenCallRealMethod(); Collection<DbRowOp> merged = action.mergeSameObjectIds(new ArrayList<>(Arrays.asList(op))); assertEquals(7, merged.size()); assertThat(merged, hasItems(op[0], op[3], op[5], op[7])); assertThat(merged, not(hasItem(sameInstance(op[1])))); assertThat(merged, not(hasItem(sameInstance(op[2])))); assertThat(merged, not(hasItem(sameInstance(op[4])))); assertThat(merged, not(hasItem(sameInstance(op[6])))); assertThat(merged, not(hasItem(sameInstance(op[8])))); assertThat(merged, not(hasItem(sameInstance(op[9])))); }