### Question:
CacheUpdateEventsStorage { @NotNull public List<IncrementalCacheUpdateEvent> getEvents() { return myEvents; }  void add(@NotNull Document document, @NotNull IncrementalCacheUpdateEvent event); @NotNull List<IncrementalCacheUpdateEvent> getEvents(); void release();  }### Answer:
@Test public void newEventLaysBeforeSingleRegistered() { int offset = myDocument.getLineStartOffset(2) + 2; change(offset, "AB"); assertEquals(1, myStorage.getEvents().size()); change(1, "12"); checkOrder(); }
@Test public void newEventLaysBetweenRegistered() { int offset = myDocument.getLineStartOffset(5) + 2; change(offset, "AB"); assertEquals(1, myStorage.getEvents().size()); checkOrder(); change(1, "CD"); assertEquals(2, myStorage.getEvents().size()); checkOrder(); offset = myDocument.getLineStartOffset(3) + 2; change(offset, "EF"); assertEquals(3, myStorage.getEvents().size()); checkOrder(); }
@Test public void mergeWithPrevious() { change(1, "AB"); assertEquals(1, myStorage.getEvents().size()); int offset = myDocument.getLineStartOffset(1) + 2; change(offset, "CD"); assertEquals(1, myStorage.getEvents().size()); IncrementalCacheUpdateEvent event = myStorage.getEvents().get(0); assertEquals(0, event.getOldStartOffset()); assertEquals(myDocument.getLineEndOffset(1), event.getOldEndOffset()); }
@Test public void mergeWithNext() { int offset = myDocument.getLineStartOffset(1) + 2; change(offset, "AB"); assertEquals(1, myStorage.getEvents().size()); change(1, "CD"); assertEquals(1, myStorage.getEvents().size()); IncrementalCacheUpdateEvent event = myStorage.getEvents().get(0); assertEquals(0, event.getOldStartOffset()); assertEquals(myDocument.getLineEndOffset(1), event.getOldEndOffset()); }
@Test public void mergePreviousAndNext() { int offset = myDocument.getLineStartOffset(2) + 2; change(offset, "AB"); assertEquals(1, myStorage.getEvents().size()); change(3, "CD"); assertEquals(2, myStorage.getEvents().size()); checkOrder(); offset = myDocument.getLineStartOffset(1) + 2; change(offset, "EF"); assertEquals(1, myStorage.getEvents().size()); IncrementalCacheUpdateEvent event = myStorage.getEvents().get(0); assertEquals(0, event.getOldStartOffset()); assertEquals(myDocument.getLineEndOffset(2), event.getOldEndOffset()); }