package gizmoball.ui.r2;

import gizmoball.NotImplementedException;
import gizmoball.game.AbsorberGizmo;
import gizmoball.game.AbstractGizmo;
import gizmoball.game.AbstractTrigger;
import gizmoball.game.BallGizmo;
import gizmoball.game.CircleBumperGizmo;
import gizmoball.game.Collidability;
import gizmoball.game.FlipperGizmo;
import gizmoball.game.OuterWallsGizmo;
import gizmoball.game.SquareBumperGizmo;
import gizmoball.game.TriangleBumperGizmo;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import physics.Vect;

/**
 * Unit tests for the R2DrawerFactory.  Tests that the
 * factory method returns the appropriate singleton 
 * instances for various classes.
 * 
 * @author Albert Leung
 * @version $Id: R2DrawerFactoryTest.java,v 1.2 2004/04/27 19:55:20 aleung Exp $
 * 
 */
public class R2DrawerFactoryTest extends TestCase {

	public static Test Suite() {
		return new TestSuite(R2DrawerFactoryTest.class);
	}
	
	public R2DrawerFactoryTest(String name) {
		super(name);
	}
	
	/*
	 * Internal imaginary gizmo class.
	 *
	 */
	private class NotRealGizmo extends AbstractGizmo {
		public NotRealGizmo() {
			super("", Vect.ZERO);
		}
		public Collidability canCollideWith(AbstractGizmo other) {
			return null;
		}
		public void collide(AbstractGizmo other) {
		}
		public void fireTrigger(AbstractTrigger trigger) {
		}
		public boolean tick(double time) {
			return false;
		}
		public double timeUntilCollisionWith(AbstractGizmo other) {
			return 0;
		}
	}

	public void testFactory() {
		AbstractGizmo abs = new AbsorberGizmo();
		AbstractGizmo ball = new BallGizmo();
		AbstractGizmo ow = new OuterWallsGizmo(new Vect(20,20));
		AbstractGizmo sq = new SquareBumperGizmo();
		AbstractGizmo tri = new TriangleBumperGizmo();
		AbstractGizmo un = new NotRealGizmo();
		AbstractGizmo fl = new FlipperGizmo();
		AbstractGizmo ci = new CircleBumperGizmo();
		
		assertEquals("returns wrong drawer for absorber",
			R2PolygonDrawer.DRAWER, R2DrawerFactory.getDrawer(abs));
		assertEquals("returns wrong drawer for ball",
					R2BallDrawer.DRAWER, R2DrawerFactory.getDrawer(ball));
		assertEquals("returns wrong drawer for outer walls",
					R2PolygonDrawer.DRAWER, R2DrawerFactory.getDrawer(ow));
		assertEquals("returns wrong drawer for square bumper",
					R2PolygonDrawer.DRAWER, R2DrawerFactory.getDrawer(sq));
		assertEquals("returns wrong drawer for triangle bumper",
					R2PolygonDrawer.DRAWER, R2DrawerFactory.getDrawer(tri));
		assertEquals("returns wrong drawer for flipper",
					R2FlipperDrawer.DRAWER, R2DrawerFactory.getDrawer(fl));
		assertEquals("returns wrong drawer for circle bumper",
					R2CircleDrawer.DRAWER, R2DrawerFactory.getDrawer(ci));
		try {
			R2DrawerFactory.getDrawer(un);
			assertTrue("does not throw exception for unsupported gizmo", false);
		}
		catch (Exception e) {
			assertTrue("wrong exception thrown", e instanceof NotImplementedException);
		}
	}
}
