/*
 * Created on 01.03.2005
 *
 * $Id$
 */
package verkehrs.test;

import java.awt.*;

import verkehrs.*;
import verkehrs.AmpelView;
import junit.framework.TestCase;

public class AmpelViewTest extends TestCase {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(AmpelViewTest.class);
    }
    
    static private AmpelView ampelView = null;
    private Frame frame = null;

    protected void setUp() throws Exception {
        if (ampelView == null) {
            ampelView = new AmpelView();
            frame = new Frame("Test-Ampel");
            frame.setLayout(new BorderLayout());
            ampelView.init();
            frame.add(ampelView, "Center");
            frame.setSize(200, 400);
            frame.setVisible(true);
            ampelView.start();
        }
    }
    
    protected void tearDown() throws Exception {
        ampelView.stop();
        super.tearDown();
    }

    public final void testRegistration() {
        AmpelModel ampelModel = ampelView.getAmpelModel();
        assertEquals(1, ampelModel.countObservers());
    }
    
    /*
     * Class under test for void update(Observable, Object)
     */
    public final void testUpdateObservableObject() throws InterruptedException {
        AmpelModel ampelModel = ampelView.getAmpelModel();
        for (int i = 0; i < 5; i++) {
            Thread.sleep(100);
            ampelModel.nextState();
        }
    }

}
