SamplerFunctions { public static <T> SamplerFunction<T> nullSafe(SamplerFunction<T> delegate) { if (delegate == null) throw new NullPointerException("delegate == null"); if (delegate instanceof Constants || delegate instanceof NullSafe) return delegate; return new NullSafe<>(delegate); }  static SamplerFunction<T> nullSafe(SamplerFunction<T> delegate); static SamplerFunction<T> deferDecision(); static SamplerFunction<T> neverSample();  }
@Test public void nullSafe_returnsNullOnNull() { assertThat(nullSafe(o -> { throw new NullPointerException(); }).trySample(null)).isNull(); }
@Test public void nullSafe_passesOnNotNull() { assertThat(nullSafe(o -> true).trySample("1")).isTrue(); }
@Test public void nullSafe_doesntDoubleWrap() { SamplerFunction<Object> sampler = nullSafe(o -> { throw new NullPointerException(); }); assertThat(sampler).isSameAs(sampler); }