@SafeVarargs public static <T> Donor<T> theSame(Instantiator<T> instantiator, PropertyValue<? super T, ?> ... propertyProviders) { return theSame(an(instantiator, propertyProviders)); }
@SafeVarargs public static <T> Donor<T> theSame(Instantiator<T> instantiator, PropertyValue<? super T, ?> ... propertyProviders) { return theSame(an(instantiator, propertyProviders)); }
@Override public AppleCart instantiate(PropertyLookup<AppleCart> lookup) { return new AppleCart(lookup.valueOf(apples, listOf(an(Apple)))); } };
@Test public void distinctCollectionElementsAreUsedForEachMadeObjectWhenElementsAreDefinedWithAMaker() { Maker<SecretAgent> anAgent = a(SecretAgent, with(assumedIdentities, listOf( an(Identity, with(name, "jason bourne")), an(Identity, with(name, "james bond"))))); SecretAgent x = make(anAgent); SecretAgent y = make(anAgent); assertThat(x.assumedIdentities, not(sameInstance(y.assumedIdentities))); assertThat(x.assumedIdentities.get(0), not(sameInstance(y.assumedIdentities.get(0)))); assertThat(x.assumedIdentities.get(1), not(sameInstance(y.assumedIdentities.get(1)))); }
public static void howToMakeObjectsWithPropertiesThatAreCollections() { AppleCart cart = make(a(AppleCart, with(apples, listOf( an(Apple, with(ripeness, 0.5)), an(Apple, with(ripeness, 0.35)) )))); FruitBowl bowl = make(a(FruitBowl, with(contents, listOf( an(Apple, with(2, leaves)), an(Apple, with(3, leaves)), a(Banana, with(ripeness, 0.25)), a(Banana, with(ripeness, 0.99)) )))); }
@Override public FruitBowl instantiate(PropertyLookup<FruitBowl> lookup) { return new FruitBowl( lookup.valueOf(contents, listOf(an(Apple), a(Banana)).value())); } };
@Test public void canDeclareThatSameCollectionIsUsedForEveryMadeObject() { Maker<SecretAgent> anAgent = a(SecretAgent, with(assumedIdentities, theSame(listOf( an(Identity, with(name, "jason bourne")), an(Identity, with(name, "james bond")))))); SecretAgent x = make(anAgent); SecretAgent y = make(anAgent); assertThat(x.assumedIdentities, sameInstance(y.assumedIdentities)); } }
@Test public void aDistinctPropertyValueInstanceIsUsedForEachMadeObjectWhenPropertyIsDefinedWithAMaker() { Maker<Identified> anIdentified = an(Identified, with(identity, a(Identity, with(name, "original-name")))); Identified x = make(anIdentified); Identified y = make(anIdentified); assertThat(x.identity, not(sameInstance(y.identity))); }
@Test public void canExplicitlyDeclareThatDifferentInstancesHaveTheSamePropertyValueInstance() { Maker<Identified> anIdentified = an(Identified, with(identity, theSame(Identity, with(name, "original-name")))); Identified x = make(anIdentified); Identified y = make(anIdentified); assertThat(x.identity, sameInstance(y.identity)); }
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))); }