Package com.sirenian.hellbound.engine

Source Code of com.sirenian.hellbound.engine.PseudoRandomGlyphFactoryBehaviour

package com.sirenian.hellbound.engine;

import org.jbehave.core.Ensure;
import org.jbehave.core.minimock.UsingMiniMock;
import org.jbehave.core.mock.Mock;

import com.sirenian.hellbound.domain.glyph.GlyphListener;
import com.sirenian.hellbound.domain.glyph.GlyphType;
import com.sirenian.hellbound.domain.glyph.Junk;
import com.sirenian.hellbound.domain.glyph.LivingGlyph;
import com.sirenian.hellbound.util.Listener;
import com.sirenian.hellbound.util.ListenerSet;

public class PseudoRandomGlyphFactoryBehaviour extends UsingMiniMock {

    public void shouldCreateLivingGlyphsPseudoRandomly() {
       
        PseudoRandomGlyphFactory factory = new PseudoRandomGlyphFactory(42, 7, 13);
        GlyphType[] expected = new GlyphType[] { GlyphType.T,
                GlyphType.Z, GlyphType.S, GlyphType.J, GlyphType.Z,
                GlyphType.L, GlyphType.T, GlyphType.J, GlyphType.S,
                GlyphType.J, GlyphType.J, GlyphType.L, GlyphType.O,
                GlyphType.O, GlyphType.T, GlyphType.J, GlyphType.O,
                GlyphType.Z, GlyphType.O, GlyphType.I, GlyphType.Z
               
        };
       
        for (int i = 0; i < 21; i++) {
            Ensure.that(nextGlyphType(factory) == expected[i]);
        }
    }
   
    public void shouldAddListenersToTheGlyphsThatItCreates() {
        ListenerSet listenerSet = new ListenerSet();
        Mock listener = mock(GlyphListener.class);
        listenerSet.addListener((Listener) listener);
       
        PseudoRandomGlyphFactory factory = new PseudoRandomGlyphFactory(42, 7, 13);
        LivingGlyph glyph = factory.nextGlyph(CollisionDetector.NULL, listenerSet);
        Junk junk = factory.createJunk(listenerSet);
       
        listener.expects("reportGlyphMovement").times(2); // once for junk change, once for glyph change
       
        junk.absorb(glyph);
    }

    private GlyphType nextGlyphType(PseudoRandomGlyphFactory factory) {
        return factory.nextGlyph(CollisionDetector.NULL, new ListenerSet()).type();
    }
}
TOP

Related Classes of com.sirenian.hellbound.engine.PseudoRandomGlyphFactoryBehaviour

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.