StateHistory { public S removeLast() { return removeLast(1); } StateHistory(
      @NonNull final String sourceName,
      @NonNull final Repository<Collection<S>> repository,
      @NonNull final MysqlSourceMetrics metrics);  StateHistory(
      @NonNull final String sourceName,
      @Min(1) final int capacity,
      @NonNull final Repository<Collection<S>> repository,
      @NonNull final MysqlSourceMetrics metrics); void add(final S state); S removeLast(); S removeLast(int count); void clear(); boolean isEmpty(); int size();  }
@Test(expected = IllegalStateException.class) public void testRemoveFromEmptyHistory() throws Exception { StateHistory<MysqlSourceState> history = new StateHistory<>(SOURCE_NAME, 2, new TestRepository(), metrics); history.removeLast(); }
@Test(expected = IllegalStateException.class) public void testRemoveMoreElementsThanInHistory() throws Exception { MysqlSourceState firstState = mock(MysqlSourceState.class); MysqlSourceState secondState = mock(MysqlSourceState.class); TestRepository repository = new TestRepository(firstState, secondState); StateHistory<MysqlSourceState> history = new StateHistory<>(SOURCE_NAME, 2, repository, metrics); history.removeLast(3); }
@Test public void testRemoveMultipleElementsFromHistory() throws Exception { MysqlSourceState firstState = mock(MysqlSourceState.class); MysqlSourceState secondState = mock(MysqlSourceState.class); MysqlSourceState thirdState = mock(MysqlSourceState.class); TestRepository repository = new TestRepository(firstState, secondState, thirdState); StateHistory<MysqlSourceState> history = new StateHistory<>(SOURCE_NAME, 3, repository, metrics); assertEquals(secondState, history.removeLast(2)); assertEquals(Collections.singletonList(firstState), repository.get()); }