/*
 * Created on 11.02.2005
 *
 * $Id: TaxiTest.java,v 1.1 2005/06/24 13:56:05 boehm Exp $
 */
package space.test;

import junit.framework.TestCase;
import space.*;
import space.annotation.Test;
import space.inhabitant.*;

/**
 * @author <a href="mailto:boehm@javatux.de">oliver</a>
 * @since 11.02.2005
 * @version $revision$
 */
@Test
public class TaxiTest extends TestCase {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(TaxiTest.class);
    }
    
    private static Taxi taxi = null;

    /**
     * Wir testen immer mit demselben (leeren) Taxi
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        if (taxi == null) {
            taxi = new Taxi();
        } else {
            taxi.leaveAll();
        }
    }
    
    protected void tearDown() throws Exception {
        super.tearDown();
        taxi.leaveAll();
    }
    
    public void testTaxi() {
        assertTrue(taxi.isOK());
    }
    
    public void testIsEmpty() {
        assertEquals(0, taxi.getNoPassengers());
        assertTrue(taxi.isEmpty());
    }
    
    public void testEnter() throws PassengerException {
        Passenger bully = new Earthling("Bully");
        taxi.enter(bully);
        assertEquals(1, taxi.getNoPassengers());
        assertEquals(bully, taxi.getPassenger(1));
    }
    
    public void testLeave() throws PassengerException {
        fillTaxi();
        taxi.leave(2);
        assertEquals(3, taxi.getNoPassengers());
    }
    
    public void testIsFull() throws PassengerException {
        fillTaxi();
        assertTrue(taxi.isFull());
    }
    
    public void testOverfillTaxi() {
        fillTaxi();
        try {
            taxi.enter(new Klingon("Xr"));
            fail("Exception expected");
        } catch (Exception expected) {}
    }
    
    private void fillTaxi() {
        try {
            for (int i = 5; i < 9; i++) {
                taxi.enter(new Earthling("Mr. 00" + i));
            }
        } catch (PassengerException unexpected) {
            fail("unexpected exception " + unexpected);
        }
    }

    public void testIsOK() {
        assertTrue(taxi.isOK());
    }

}
