DeduplicatingVoidCallFactory { public final void maybeAdd(I input, List<Call<Void>> calls) { if (input == null) throw new NullPointerException("input == null"); if (!delayLimiter.shouldInvoke(input)) return; calls.add(new InvalidatingVoidCall<>(newCall(input), delayLimiter, input)); } protected  DeduplicatingVoidCallFactory(long ttl, int cardinality); final void maybeAdd(I input, List<Call<Void>> calls); void clear();  }
@Test public void dedupesSameCalls() throws Exception { List<Call<Void>> calls = new ArrayList<>(); callFactory.maybeAdd("foo", calls); callFactory.maybeAdd("bar", calls); callFactory.maybeAdd("foo", calls); callFactory.maybeAdd("bar", calls); callFactory.maybeAdd("bar", calls); assertThat(calls).hasSize(2); for (Call<Void> call : calls) { call.execute(); } assertThat(values).containsExactly("foo", "bar"); }
@Test public void enqueuesInOrder() { List<Call<Void>> calls = new ArrayList<>(); callFactory.maybeAdd("foo", calls); callFactory.maybeAdd("bar", calls); for (Call<Void> call : calls) { call.enqueue(assertFailOnError); } assertThat(values).containsExactly("foo", "bar"); }