Package com.tobedevoured.modelcitizen.model

Examples of com.tobedevoured.modelcitizen.model.Car


    }

    @Test
    public void testFieldNull() throws CreateModelException {

        Car car = modelFactory.createModel(Car.class);
        assertNull(car.getPassenger());
    }
View Full Code Here


        erector.setNewInstance(null);
    }

    @Test
    public void testGet() throws BlueprintTemplateException {
        Car car = new Car();
        car.setMileage(new Float(123.456));
        Float val = (Float) erector.getTemplate().get(car, "mileage");
        assertEquals(new Float(123.456), val);
    }
View Full Code Here

    }

    @Test
    public void testNestedMappedLists() throws CreateModelException {

        Car car = modelFactory.createModel(Car.class);

        assertEquals(4, car.getWheels().size());

        for (Wheel wheel : car.getWheels()) {
            assertEquals("tire name", wheel.getName());
            assertEquals(3, wheel.getOptions().size());
            for (Option option : wheel.getOptions()) {
                assertEquals("option", option.getName());
            }
View Full Code Here

    }

    @Test
    public void testForceAlwaysCreatesMappedList() throws CreateModelException {

        Car car = new Car();
        car.setWheels(Arrays.asList(new Wheel[]{new Wheel("test")}));
        car = modelFactory.createModel(car);

        assertEquals("force=true ensures wheels will be injected", 4, car.getWheels().size());
    }
View Full Code Here

    @Test
    public void singletonPolicyWithClass() throws ModelFactoryException {
        modelFactory.addPolicy(new MappedSingletonPolicy(Driver.class));

        Car car1 = modelFactory.createModel(Car.class);
        Car car2 = modelFactory.createModel(Car.class);
        Car car3 = modelFactory.createModel(Car.class);

        Driver driver = car1.getDriver();

        assertEquals(car2.getDriver(), driver);
        assertEquals(car3.getDriver(), driver);
    }
View Full Code Here

    @Test
    public void singletonPolicyWithModel() throws ModelFactoryException {
        Driver driver = modelFactory.createModel(Driver.class);
        modelFactory.addPolicy(new MappedSingletonPolicy(driver));

        Car car1 = modelFactory.createModel(Car.class);
        Car car2 = modelFactory.createModel(Car.class);
        Car car3 = modelFactory.createModel(Car.class);

        assertEquals(car1.getDriver(), driver);
        assertEquals(car2.getDriver(), driver);
        assertEquals(car3.getDriver(), driver);
    }
View Full Code Here

    }

    @Test
    public void testCreateModelWithClass() throws RegisterBlueprintException, CreateModelException {

        Car car = modelFactory.createModel(Car.class);
        assertEquals(carBlueprint.make, car.getMake());
        assertEquals(carBlueprint.manufacturer, car.getManufacturer());
        assertEquals(carBlueprint.status, car.getStatus());
        assertEquals(4, car.getWheels().size());

        for (Wheel wheel : car.getWheels()) {
            assertEquals(wheelBlueprint.size, wheel.getSize());
        }
    }
View Full Code Here

    }


    @Test
    public void testBlueprintWithPrimitive() throws CreateModelException, BlueprintTemplateException {
        Car car = modelFactory.createModel(Car.class);

        Erector erector = modelFactory.getErectors().get(Car.class);

        ModelField modelField = erector.getModelField("mileage");
        assertEquals(new Float(100.1), modelField.getValue());

        // Val is zero because primitive initializes as zero
        Object val = erector.getTemplate().get(new Car(), "mileage");
        assertEquals(new Float(0.0), val);

        // Val is zero because primitive initializes as zero
        assertEquals(0.0, car.getMileage(), 0);
    }
View Full Code Here

    }

    @Test
    public void testCreateModelWithModel() throws RegisterBlueprintException, CreateModelException {

        Car car = modelFactory.createModel(new Car());
        assertEquals(carBlueprint.make, car.getMake());
        assertEquals(carBlueprint.manufacturer, car.getManufacturer());
        assertEquals(new Float(0.0), new Float(car.getMileage()));
        assertEquals(carBlueprint.status, car.getStatus());
        assertEquals(4, car.getWheels().size());

        for (Wheel wheel : car.getWheels()) {
            assertEquals(wheelBlueprint.size, wheel.getSize());
        }

        assertEquals(1, car.getSpares().size());
        for (Wheel wheel : car.getSpares()) {
            assertEquals(wheelBlueprint.size, wheel.getSize());
        }

        car.setMake("new make");
        car.setManufacturer("test manuf");

        car.setWheels(new ArrayList<Wheel>());
        Wheel wheel = new Wheel("mega tire");
        car.getWheels().add(wheel);

        car.setSpares(new HashSet<Wheel>());

        car = modelFactory.createModel(car);
        assertEquals("new make", car.getMake());
        assertEquals("test manuf", car.getManufacturer());
        assertEquals(0.0, car.getMileage(), 0);
        assertEquals(carBlueprint.status, car.getStatus());


        assertEquals("Car Wheels blueprint forced to the mapping of 4", 4, car.getWheels().size());
        assertEquals("The Car reference model should have 0 spares", 0, car.getSpares().size());
    }
View Full Code Here

        modelFactory.registerBlueprint(CarBlueprint.class);
    }

    @Test
    public void carAfterCreateCallback() throws CreateModelException {
        Car car = modelFactory.createModel(Car.class);

        for( Wheel wheel: car.getWheels() ) {
            assertEquals(car, wheel.getCar());
        }
    }
View Full Code Here

TOP

Related Classes of com.tobedevoured.modelcitizen.model.Car

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.