Package org.andromda.translation.ocl.validation

Source Code of org.andromda.translation.ocl.validation.OCLCollectionsTest

package org.andromda.translation.ocl.validation;

import junit.framework.TestCase;
import org.apache.commons.collections.Transformer;

import java.util.ArrayList;
import java.util.Collection;

/**
* Tests the OCLCollections
*
* @author Chad Brandon
*/
public class OCLCollectionsTest extends TestCase
{

    /**
     * Constructor for OCLCollectionsTest.
     *
     * @param name the test name
     */
    public OCLCollectionsTest(String name)
    {
        super(name);
    }

    /**
     * Tests isUnique
     */
    public void testIsUnique()
    {
        Collection collection = new ArrayList();
        OCLCollectionsTestObject testObject = new OCLCollectionsTestObject();
        testObject.setPropertyOne("propertyOne");
        collection.add(testObject);
        testObject = new OCLCollectionsTestObject();
        testObject.setPropertyOne("propertyOneAgain");
        collection.add(testObject);
        assertEquals(2, collection.size());
        assertTrue(OCLCollections.isUnique(collection, new Transformer()
        {
            public Object transform(Object object)
            {
                return OCLIntrospector.invoke(object, "propertyOne");
            }

        }));
        assertTrue(OCLCollections.isUnique((Object) collection, new Transformer()
        {
            public Object transform(Object object)
            {
                return OCLIntrospector.invoke(object, "propertyOne");
            }

        }));
        testObject = new OCLCollectionsTestObject();
        testObject.setPropertyOne("propertyOne");
        collection.add(testObject);
        assertEquals(3, collection.size());
        assertFalse(OCLCollections.isUnique(collection, new Transformer()
        {
            public Object transform(Object object)
            {
                return OCLIntrospector.invoke(object, "propertyOne");
            }

        }));
        assertFalse(OCLCollections.isUnique((Object) collection, new Transformer()
        {
            public Object transform(Object object)
            {
                return OCLIntrospector.invoke(object, "propertyOne");
            }

        }));
        collection.remove(testObject);
        assertEquals(2, collection.size());
        assertTrue(OCLCollections.isUnique(collection, new Transformer()
        {
            public Object transform(Object object)
            {
                return OCLIntrospector.invoke(object, "propertyOne");
            }

        }));
        assertTrue(OCLCollections.isUnique((Object) collection, new Transformer()
        {
            public Object transform(Object object)
            {
                return OCLIntrospector.invoke(object, "propertyOne");
            }

        }));
    }

}
TOP

Related Classes of org.andromda.translation.ocl.validation.OCLCollectionsTest

TOP
Copyright © 2018 www.massapi.com. 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.