@Test public void sharingDefinitionsAvoidsAliasingErrors() { Maker<ThingToMake> x99Maker = a(ThingToMake, with(name, "x"), with(age, 99)); Maker<ThingToMake> x77Maker = x99Maker.but(with(age, 77)); ThingToMake x99 = x99Maker.make(); ThingToMake x77 = x77Maker.make(); assertThat("x99.name", x99.name, equalTo("x")); assertThat("x77.name", x77.name, equalTo("x")); assertThat("x99.age", x99.age, equalTo(99)); assertThat("x77.age", x77.age, equalTo(77)); } }
public static void howToMakeSimpleObjects() { Maker<Apple> appleWith2Leaves = an(Apple, with(2, leaves)); Maker<Apple> ripeApple = appleWith2Leaves.but(with(ripeness, 0.9)); Maker<Apple> unripeApple = appleWith2Leaves.but(with(ripeness, 0.125)); Apple apple1 = make(ripeApple); Apple apple2 = make(unripeApple); Banana defaultBanana = make(a(Banana)); Banana straightBanana = make(a(Banana, with(curve, 0.0))); Banana squishyBanana = make(a(Banana, with(ripeness, 1.0))); }