MultiDataWriter implements DataWriter<T> { @Override public Future<T> loadAndGet() { return comparators.map(c -> c.loadAndGet()) .foldLeft((acc, next) -> acc.zip(next, (v1, v2) -> v1)) .orElse(Future.ofResult(null)); }  @Override Future<T> loadAndGet(); @Override Future<Void> saveAndIncrement(T data); @Override Future<Boolean> isOutOfDate();  }
@Test public void loadAndGetReturnsDataFromFirst() { dataWriter1.setData("one"); dataWriter2.setData("two"); String data = writer.loadAndGet() .orElse(null); assertThat(data, equalTo("one")); }
@Test public void loadAndGetReturnsNullForEmpty() { String data = empty.loadAndGet() .orElse("null!!"); assertThat(data, equalTo(null)); }