FilteredGenerator implements Gen<T> { public String asString(T t) { return child.asString(t); } FilteredGenerator(Gen<T> child, Predicate<T> assumption); @Override T generate(RandomnessSource in); String asString(T t);  }
@Test public void describesValuesWithToStringByDefault() { Gen<Integer> ints = Sequence.of(1); assertThat(ints.asString(42)).isEqualTo("42"); }
@Test public void describesNullValuesAsNull() { Gen<Integer> ints = Sequence.of(1); assertThat(ints.asString(aNull())).isEqualTo("null"); }
@Test public void usesProvidedFunctionToDescribeValues() { Gen<Integer> ints = Sequence.of(1,2,3,4) .describedAs( i -> "about " + i); assertThat(ints.asString(42)).isEqualTo("about 42"); }
@Test public void preservesDescriptionWhenFiltering() { Gen<Integer> ints = Sequence.of(1,2,3,4) .describedAs( i -> "about " + i) .assuming( i -> i != 2); assertThat(ints.asString(42)).isEqualTo("about 42"); }
@Test public void willLooseDescriptionWhenMappingToSameType() { Gen<Integer> ints = Sequence.of(1,2,3,4) .describedAs( i -> "about " + i) .map( i -> i + 1); assertThat(ints.asString(42)).isEqualTo("42"); }