### Question:
DataSync { public synchronized void add(final long timestamp, final T data) { DataStore store = new DataStore(timestamp, data); if (!buffer.isEmpty() && timestamp < buffer.get(0).getTimestamp()) { log.debug("Clearing buffer, since incoming timestamp is smaller than buffered timestamp (" + timestamp + "<" + buffer.get(0).getTimestamp() + ")"); buffer.clear(); } if (buffer.size() >= bufferSize) { buffer.remove(0); } buffer.add(store); } DataSync(final int bufferSize); synchronized void add(final long timestamp, final T data); synchronized Optional<DataPair> get(final long timestamp); synchronized Optional<DataStore> getLatest(); synchronized void reset();  }### Answer:
@Test public void add() { DataSync<Double> ds = new DataSync<>(10); ds.add(1, 10.0); ds.add(3, 20.0); ds.add(5, 30.0); assertThat(ds.get(0)).isNotPresent(); assertThat(ds.get(1)).isPresent(); assertThat(ds.get(2)).isPresent(); assertThat(ds.get(3)).isPresent(); assertThat(ds.get(5)).isPresent(); assertThat(ds.get(6)).isNotPresent(); DataSync<Double>.DataPair dp1 = ds.get(1).orElseThrow(AssertionFailedError::new); assertThat(dp1.getFirst().getTimestamp()).isEqualTo(1L); assertThat(dp1.getSecond().getTimestamp()).isEqualTo(3L); assertThat(dp1.getFirst().getData()).isEqualTo(10.0); assertThat(dp1.getSecond().getData()).isEqualTo(20.0); ds.add(0, 50.0); assertThat(ds.get(1)).isNotPresent(); assertThat(ds.get(0)).isNotPresent(); }