SetProducer extends AbstractProducer<Set<T>> { public static <T> Producer<Set<T>> create( @SuppressWarnings("unchecked") Producer<Set<T>>... producers) { return new SetProducer<T>(ImmutableSet.copyOf(producers)); } private  SetProducer(Set<Producer<Set<T>>> contributingProducers); static Producer<Set<T>> create(
      @SuppressWarnings("unchecked") Producer<Set<T>>... producers); @Override ListenableFuture<Set<T>> compute();  }
@Test public void success() throws Exception { Producer<Set<Integer>> producer = SetProducer.create( new ImmediateProducer<Set<Integer>>(ImmutableSet.of(1, 2)), new ImmediateProducer<Set<Integer>>(ImmutableSet.of(5, 7))); assertThat(producer.get().get()).containsExactly(1, 2, 5, 7); }
@Test public void delegateSetNpe() throws Exception { Producer<Set<Integer>> producer = SetProducer.create( new ImmediateProducer<Set<Integer>>(ImmutableSet.of(1, 2)), new ImmediateProducer<Set<Integer>>(null)); ListenableFuture<Set<Integer>> future = producer.get(); try { future.get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause()).isInstanceOf(NullPointerException.class); } }
@Test public void delegateElementNpe() throws Exception { Producer<Set<Integer>> producer = SetProducer.create( new ImmediateProducer<Set<Integer>>(ImmutableSet.of(1, 2)), new ImmediateProducer<Set<Integer>>( Collections.<Integer>singleton(null))); ListenableFuture<Set<Integer>> future = producer.get(); try { future.get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause()).isInstanceOf(NullPointerException.class); } }