import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.function.Function;

import static lib.FactoryJill.build;
import static lib.FactoryJill.factory;

public class BuildTest {

    @Before
    public void before() {
        factory("truck", Car.class, ImmutableMap.of(
                "make", "ford",
                "convertible", false,
                "yearsOwned", 5,
                "year", new Date()
        ));
    }

    @Test
    public void overrides_handlesMultipleTypes() throws Exception {
        Car ford = build("truck", ImmutableMap.of("make", "Ford"));
        assert ford.getMake().equals("Ford");

        Car convertible = build("truck", ImmutableMap.of("convertible", true));
        assert convertible.getConvertible().equals(true);

        Car wellLookedAfter = build("truck", ImmutableMap.of("yearsOwned", 13));
        assert wellLookedAfter.getYearsOwned() == 13;

        Date now = new Date();
        Car rightOffTheShelf = build("truck", ImmutableMap.of("year", now));
        assert rightOffTheShelf.getYear().equals(now);
    }

    @Test
    public void overrides_canBeDynamic() throws Exception {
        Map<String, Object> dynamicAttributes = new HashMap<>();

        Function<Car, String> lambda = (Car car) -> {
            Random random = new Random();
            Double decision = random.nextDouble();
            if (decision > .5) {
                return "Low Rider";
            } else {
                return "High Rider";
            }
        };

        dynamicAttributes.put("make", lambda);

        Car randomFord = build("truck", dynamicAttributes);

        assert randomFord.getMake().equals("Low Rider") || randomFord.getMake().equals("High Rider");
        assert randomFord.getYearsOwned() == 5;
    }

    @Test
    public void definedFactories_haveConfiguredProperties() throws Exception {
        Car pickupTruck = (Car) build("truck");

        assert pickupTruck.getMake().equals("ford");
    }
}

@@ -604,37 +604,221 @@
 oid 
-over
+definedFacto
 ri
-d
 es_ha
-ndlesMultipleType
+veConfiguredProperties() throws Exception %7B%0A        Car pickupTruck = (Car) build(%22truck%22);%0A%0A        assert pickupTruck.getMake().equals(%22ford%22);%0A    %7D%0A%0A    @Test%0A    public void overrideDefault
 s() 
@@ -1426,30 +1426,24 @@
 oid 
-overrides_canBeDynamic
+dynamicOverrides
 () t
@@ -2033,24 +2033,24 @@
 gh Rider%22);%0A
+
         asse
@@ -2094,205 +2094,7 @@
    %7D
-%0A%0A    @Test%0A    public void definedFactories_haveConfiguredProperties() throws Exception %7B%0A        Car pickupTruck = (Car) build(%22truck%22);%0A%0A        assert pickupTruck.getMake().equals(%22ford%22);%0A    %7D
 %0A%7D%0A

Order tests to be more intuitive