### Question:
TypeGenerator implements Generator<T> { @Override @SuppressWarnings("unchecked") public T next() { V next = valueGenerator.next(); lookupConstructor(typeClass, next.getClass()); try { return (T) constructor.invoke(next); } catch (Throwable throwable) { throw propagate(throwable); } } TypeGenerator(@Nonnull Class<T> typeClass, @Nonnull Generator<V> valueGenerator); @Override @SuppressWarnings("unchecked") T next();  }### Answer:
@Test public void shouldFailWhenTypeDoesNotHaveOneArgConstructor() { expectedException.expect(RuntimeException.class); TypeGenerator<Object, Integer> typeGenerator = new TypeGenerator<>(Object.class, Generators.positiveInts); typeGenerator.next(); }
@Test public void shouldPropagateExceptionWhenTypeThrowsExceptionDuringConstruction() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(MESSAGE); TypeGenerator<AlwaysThrowsException, Integer> typeGenerator = new TypeGenerator<>(AlwaysThrowsException.class, Generators.positiveInts); typeGenerator.next(); }
@Test public void shouldGenerateTypeThatHasOneArgConstructor() { Generator<WholeAmount> wholeAmountGenerator = new TypeGenerator<>(WholeAmount.class, Generators.positiveInts(12, 13)); WholeAmount wholeAmount = wholeAmountGenerator.next(); assertThat(wholeAmount, is(new WholeAmount(12))); }
@Test public void shouldGenerateTypeThatHasOneArgConstructorAndValueGeneratorIsGeneric() { TypeGenerator<WholeAmount, Integer> wholeAmountGenerator = new TypeGenerator<>(WholeAmount.class, ofInstance(13)); WholeAmount wholeAmount = wholeAmountGenerator.next(); WholeAmount expectedAmount = new WholeAmount(13); assertThat(wholeAmount, is(expectedAmount)); }
@Test public void shouldGenerateTypeThatHasOneArgConstructorAndValueGeneratorAnotherTypeGenerator() { TypeGenerator<WholeAmount, Integer> wholeAmountGenerator = new TypeGenerator<>(WholeAmount.class, ofInstance(13)); TypeGenerator<Salary, WholeAmount> salaryGenerator = new TypeGenerator<>(Salary.class, wholeAmountGenerator); Salary salary = salaryGenerator.next(); Salary expectedSalary = new Salary(new WholeAmount(13)); assertThat(salary, is(expectedSalary)); }