package org.scotlandyard.tests.engine.boardmap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import java.lang.reflect.Constructor;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.scotlandyard.engine.GameException;
import org.scotlandyard.engine.boardmap.Coordinate;
import org.scotlandyard.engine.boardmap.Link;
import org.scotlandyard.engine.constants.TransportationMethod;
import org.scotlandyard.impl.engine.GameEngine;
import org.scotlandyard.impl.engine.boardmap.BoardMapFactory;
/**
* TODO add description
*
* @author Hussain Al-Mutawa
* @version 1.0
* @since Sept 2011
*
*/
public class BoardMapFactoryTest {
@BeforeClass
public static void before() throws Exception{
GameEngine.instance().clearRecords();
BoardMapFactory.setDefaultBoardMap(BoardMapFactory.createBoardMap("Palmerston North"));
}
@AfterClass
public static void after() throws Exception{
GameEngine.instance().clearRecords();
}
@Test//TODO add description here
public void testCreateBoardMap() throws Exception{
Constructor<BoardMapFactory> c = BoardMapFactory.class.getDeclaredConstructor();
c.setAccessible(true); // solution
assertEquals(
"Test if has got access to private resources",
"org.scotlandyard.impl.engine.boardmap.BoardMapFactory : adsg31267uyydg821367uayge82367KJSDH87236e",
c.newInstance().toString()
);
}
@Test//TODO add description here
public void testCreateCoordinate() throws GameException{
final Coordinate coordinate = BoardMapFactory.createCoordinate(1, 2);
assertNotNull(
"the coordinate map should not be null",
coordinate.getBoardMap()
);
}
@Test//TODO add description here
public void testCreateLinkBoardMapTransportationMethodDoubleDoubleDoubleDouble() throws GameException{
final Link link =BoardMapFactory.createLink(TransportationMethod.UG, 0, 1, 2, 3);
final Coordinate coordinateA = link.getCoordinateA();
final Coordinate coordinateB = link.getCoordinateB();
assertNotNull(
"the link map should not be null",
link.getBoardMap()
);
assertNotNull(
"the coordinate map should not be null",
coordinateA.getBoardMap()
);
assertNotNull(
"the coordinate map should not be null",
coordinateB.getBoardMap()
);
assertEquals(
"the coordinate A latitude should be [0]",
0,
coordinateA.getLatitude(),
0
);
assertEquals(
"the coordinate B longtitude should be [3]",
3,
coordinateB.getLongtitude(),
0
);
}
@Test//TODO add description here
public void testCreateLinkTransportationMethodCoordinateCoordinate() throws GameException{
final Coordinate cA = BoardMapFactory.createCoordinate(0,1);
final Coordinate cB = BoardMapFactory.createCoordinate(2,3);
final Link link =BoardMapFactory.createLink(TransportationMethod.UG, cA, cB);
final Coordinate coordinateA = link.getCoordinateA();
final Coordinate coordinateB = link.getCoordinateB();
assertNotNull(
"the link map should not be null",
link.getBoardMap()
);
assertNotNull(
"the coordinate map should not be null",
coordinateA.getBoardMap()
);
assertNotNull(
"the coordinate map should not be null",
coordinateB.getBoardMap()
);
assertEquals(
"the coordinate A latitude should be [0]",
0,
coordinateA.getLatitude(),
0
);
assertEquals(
"the coordinate B longtitude should be [3]",
3,
coordinateB.getLongtitude(),
0
);
assertSame(
"coordinate B == coB",
cB,
coordinateB
);
assertSame(
"coordinate A == coA",
cA,
coordinateA
);
}
}