@Override public T value() { return make(); }
/** * Returns a new Maker for the same type of object and with the same initial state * except where overridden by the given <var>propertyValues</var>. * * @param propertyValues those initial properties of the new Make that will differ from this Maker * @return a new Maker */ @SafeVarargs public final Maker<T> but(PropertyValue<? super T, ?>... propertyValues) { return new Maker<>(this, propertyValues); }
/** * Creates a Maker for objects of a given type with a given initial state. * * @param instantiator creates the new objects * @param propertyValues define the initial state of the new objects */ @SafeVarargs public Maker(Instantiator<T> instantiator, PropertyValue<? super T, ?>... propertyValues) { this.instantiator = instantiator; this.values = byProperty(propertyValues); }
@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)); } }
@Override public <V> V valueOf(Property<? super T, V> property, V defaultValue) { return valueOf(property, new SameValueDonor<>(defaultValue)); }
public static <T> T make(Maker<T> maker) { return maker.value(); }
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))); }
@Override public <V> V valueOf(Property<? super T, V> property, V defaultValue) { return valueOf(property, new SameValueDonor<>(defaultValue)); }
public static <T> T make(Maker<T> maker) { return maker.value(); }
/** * Returns a new Maker for the same type of object and with the same initial state * except where overridden by the given <var>propertyValues</var>. * * @param propertyValues those initial properties of the new Make that will differ from this Maker * @return a new Maker */ @SafeVarargs public final Maker<T> but(PropertyValue<? super T, ?>... propertyValues) { return new Maker<>(this, propertyValues); }
@Override public T value() { return make(); }
/** * Creates a Maker for objects of a given type with a given initial state. * * @param instantiator creates the new objects * @param propertyValues define the initial state of the new objects */ @SafeVarargs public Maker(Instantiator<T> instantiator, PropertyValue<? super T, ?>... propertyValues) { this.instantiator = instantiator; this.values = byProperty(propertyValues); }
@SafeVarargs public static <T> Maker<T> a(Instantiator<T> instantiator, PropertyValue<? super T, ?> ... propertyProviders) { return new Maker<>(instantiator, propertyProviders); }
@SafeVarargs private Maker(Maker<T> that, PropertyValue<? super T, ?>... propertyValues) { this.instantiator = that.instantiator; this.values = that.values.plusAll(byProperty(propertyValues)); }
@SafeVarargs public static <T> Maker<T> an(Instantiator<T> instantiator, PropertyValue<? super T, ?> ... propertyProviders) { return new Maker<>(instantiator, propertyProviders); }
@SafeVarargs private Maker(Maker<T> that, PropertyValue<? super T, ?>... propertyValues) { this.instantiator = that.instantiator; this.values = that.values.plusAll(byProperty(propertyValues)); }
@SafeVarargs public static <T> Maker<T> an(Instantiator<T> instantiator, PropertyValue<? super T, ?> ... propertyProviders) { return new Maker<>(instantiator, propertyProviders); }
@SafeVarargs public static <T> Maker<T> a(Instantiator<T> instantiator, PropertyValue<? super T, ?> ... propertyProviders) { return new Maker<>(instantiator, propertyProviders); }