001/*
002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
003 * Copyright (C) 2000-2011 The Gridarta Developers.
004 *
005 * This program is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation; either version 2 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License along
016 * with this program; if not, write to the Free Software Foundation, Inc.,
017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
018 */
019
020package net.sf.gridarta.model.archetypeset;
021
022import java.util.Collection;
023import java.util.Iterator;
024import net.sf.gridarta.model.anim.AnimationObjects;
025import net.sf.gridarta.model.anim.TestAnimationObjects;
026import net.sf.gridarta.model.archetype.ArchetypeFactory;
027import net.sf.gridarta.model.archetype.DuplicateArchetypeException;
028import net.sf.gridarta.model.archetype.TestArchetype;
029import net.sf.gridarta.model.archetype.TestArchetypeFactory;
030import net.sf.gridarta.model.archetype.TestDefaultArchetype;
031import net.sf.gridarta.model.face.FaceObjectProviders;
032import net.sf.gridarta.model.face.FaceObjects;
033import net.sf.gridarta.model.face.TestFaceObjects;
034import net.sf.gridarta.model.gameobject.TestGameObject;
035import net.sf.gridarta.model.maparchobject.TestMapArchObject;
036import net.sf.gridarta.utils.ResourceIcons;
037import org.junit.Assert;
038import org.junit.Test;
039
040/**
041 * Regression tests for {@link DefaultArchetypeSet}.
042 * @author Andreas Kirschbaum
043 */
044public class DefaultArchetypeSetTest {
045
046    /**
047     * Checks that archetypes are returned in load order.
048     * @throws DuplicateArchetypeException if the test fails
049     */
050    @Test
051    public void testRetainLoadOrder() throws DuplicateArchetypeException {
052        final FaceObjects faceObjects = new TestFaceObjects();
053        final ResourceIcons resourceIcons = new ResourceIcons();
054        final FaceObjectProviders faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
055        final AnimationObjects animationObjects = new TestAnimationObjects();
056        final ArchetypeFactory<TestGameObject, TestMapArchObject, TestArchetype> archetypeFactory = new TestArchetypeFactory(faceObjectProviders, animationObjects);
057        final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> archetypeSet = new DefaultArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype>(archetypeFactory, null);
058        archetypeSet.addArchetype(new TestDefaultArchetype("b", faceObjectProviders, animationObjects));
059        archetypeSet.addArchetype(new TestDefaultArchetype("d", faceObjectProviders, animationObjects));
060        archetypeSet.addArchetype(new TestDefaultArchetype("c", faceObjectProviders, animationObjects));
061        archetypeSet.addArchetype(new TestDefaultArchetype("e", faceObjectProviders, animationObjects));
062        archetypeSet.addArchetype(new TestDefaultArchetype("a", faceObjectProviders, animationObjects));
063        final Collection<TestArchetype> archetypes = archetypeSet.getArchetypes();
064        Assert.assertEquals(5, archetypes.size());
065        final Iterator<TestArchetype> it = archetypes.iterator();
066        Assert.assertEquals("b", it.next().getArchetypeName());
067        Assert.assertEquals("d", it.next().getArchetypeName());
068        Assert.assertEquals("c", it.next().getArchetypeName());
069        Assert.assertEquals("e", it.next().getArchetypeName());
070        Assert.assertEquals("a", it.next().getArchetypeName());
071        Assert.assertFalse(it.hasNext());
072    }
073
074}