Source

izi / izi / test / org / izi / beans / TestBeanContainer.as

Full commit
/**
 * Copyright (C) 2010 Sabre Polska, All rights reserved.
 *
 * This software is the confidential and proprietary product of Sabre Polska.
 * Any unauthorized use, reproduction, or transfer of this software is
 * strictly prohibited.
 *
 * Date: Aug 26, 2010
 */
package org.izi.beans
{
import flash.events.Event;

import flexunit.framework.TestCase;

public class TestBeanContainer extends TestCase
{
    public function TestBeanContainer()
    {
        super();
    }

    public function testShouldAllowAddingPropertiesDynamically():void
    {
        // given
        var container:BeanContainer = new BeanContainer();
        container.dynamicBean = new Bean();
        container.dependency = new Dependency();
        // when
        container.initialize(null);
        // then
        assertNotNull(container.dynamicBean.dependency);
    }

    public function testShouldAllowAutowireWithAMockContextSet():void
    {
        // given
        var someContainer:SomeContainer = new SomeContainer();
        var mockBeans:BeanContainer = new BeanContainer();
        mockBeans.dependency = new Dependency();
        someContainer.context.parent = mockBeans;
        // when
        someContainer.dispatchEvent(new Event(BeanContainer.CONTAINER_CREATION_EVENT));
        // then
        assertNotNull(someContainer.bean);
    }

    public function testShouldNotGetIntoRecursionOnHasBeanWhenBeanNotDefined():void
    {
        // given
        var mockBeans:BeanContainer = new BeanContainer();
        mockBeans.includeBeans = [ BeanContainer ];
        mockBeans.initialize(null);
        // when
        var hasBean:Boolean = mockBeans.hasBean("somethingNotExisting");
        // then
        assertFalse(hasBean);
    }

    public function testShouldNotGetIntoRecursionWhenIncludeMultipleContainers():void
    {
        var mockBeans:BeanContainer = new BeanContainer();
        mockBeans.includeBeans = [ ChildBeans, MainContext ];
        mockBeans.initialize(null);

        // when
        var bean:Object = mockBeans.getBean("anotherBean");

        // then
        assertNotNull(bean);
    }
}
}