Package org.scotlandyard.tests.engine.boardmap

Source Code of org.scotlandyard.tests.engine.boardmap.LinkTest

package org.scotlandyard.tests.engine.boardmap;


import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.scotlandyard.engine.GameException;
import org.scotlandyard.engine.boardmap.BoardMap;
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.BoardMapImpl;
import org.scotlandyard.impl.engine.boardmap.CoordinateImpl;
import org.scotlandyard.impl.engine.boardmap.LinkImpl;

/**
* TODO add description
*
* @author Hussain Al-Mutawa
* @version 1.0
* @since Sept 2011
*
*/
public class LinkTest {

  private transient final BoardMap boardMap,boardMap2;
  private transient Link link;
  private transient Coordinate a,b;
  //TODO add description here
  public LinkTest() throws Exception {
    boardMap = BoardMapImpl.getNewInstance("Palmerston North");
    boardMap2 = BoardMapImpl.getNewInstance("Auckland");
  }

  @Before//TODO add description here
  public void setUp() throws Exception{
    a = new CoordinateImpl(boardMap, 10, 20);
    b = new CoordinateImpl(boardMap, 12, 22);
    link = new LinkImpl(boardMap, TransportationMethod.BUS, a, b);
  }

  @After//TODO add description here
  public void tearDown() throws Exception{
    GameEngine.instance().getBoardMaps().remove("Auckland");
  }
 
  @Test//TODO add description here
  public final void testEqualsObject() throws GameException{
    Link other = new LinkImpl(boardMap, TransportationMethod.BUS, a, b);
    Assert.assertTrue(link.equals(other));
    Link other2 = new LinkImpl(boardMap, TransportationMethod.TAXI, a, b);
    Assert.assertFalse(link.equals(other2));
    Link other3 = new LinkImpl(boardMap, TransportationMethod.BUS, a, new CoordinateImpl(boardMap,11,22));
    Assert.assertFalse(link.equals(other3));
    Link other4 = new LinkImpl(boardMap, TransportationMethod.BUS, new CoordinateImpl(boardMap,11,20), b);
    Assert.assertFalse(link.equals(other4));
  }

  @Test//TODO add description here
  public final void testGetBoardMap() {
    Assert.assertSame(link.getBoardMap(),boardMap);
    Assert.assertNotSame(link.getBoardMap(),boardMap2);
  }

  @Test//TODO add description here
  public final void testGetCoordinateA() {
    Assert.assertSame(link.getOtherEnd(a),b);
    Assert.assertSame(link.getOtherEnd(a),link.getCoordinateB());
  }

  @Test//TODO add description here
  public final void testGetCoordinateB() {
    Assert.assertSame(link.getOtherEnd(b),a);
    Assert.assertSame(link.getOtherEnd(b),link.getCoordinateA());
  }

  @Test//TODO add description here
  public final void testGetOtherEnd() {
    Assert.assertNotSame(link.getOtherEnd(a),link.getCoordinateA());
    Assert.assertNotSame(link.getOtherEnd(b),link.getCoordinateB());
  }

  @Test//TODO add description here
  public final void testGetTransportationMethod() throws Exception{
    Assert.assertEquals(link.getTransportationMethod(), TransportationMethod.BUS);
  }

  @Test//TODO add description here
  public final void testLinkImpl1() {
    Assert.assertEquals(link.getCoordinateA(),a);
    Assert.assertEquals(link.getCoordinateB(),b);
    Assert.assertEquals(link.getBoardMap(), boardMap);
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl2() throws Exception{
    Assert.assertNull(new LinkImpl(
        null,
        TransportationMethod.BUS,
        new CoordinateImpl(boardMap, 2, 2),
        new CoordinateImpl(boardMap, 1, 1)
    ));
   
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl3() throws Exception{
    Assert.assertNull(new LinkImpl(
        boardMap,
        null,
        new CoordinateImpl(boardMap, 2, 2),
        new CoordinateImpl(boardMap, 1, 1)
    ));
   
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl4() throws Exception{
    Assert.assertNull(new LinkImpl(
        boardMap,
        TransportationMethod.BUS,
        null,
        new CoordinateImpl(boardMap, 1, 1)
    ));
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl5() throws Exception{
    Assert.assertNull(new LinkImpl(
        boardMap,
        TransportationMethod.BUS,
        new CoordinateImpl(boardMap, 2, 2),
        null
    ));
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl6() throws Exception{
    Assert.assertNull(new LinkImpl(
        boardMap,
        TransportationMethod.BUS,
        new CoordinateImpl(boardMap, 12, 22),
        new CoordinateImpl(boardMap2, 12, 22)
    ));
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl7() throws Exception{
    Assert.assertNull(new LinkImpl(
        boardMap,
        TransportationMethod.BUS,
        new CoordinateImpl(boardMap2, 12, 22),
        new CoordinateImpl(boardMap, 12, 22)
    ));
  }

  @Test(expected=Exception.class)//TODO add description here
  public final void testLinkImpl8() throws Exception{
    Assert.assertNull(new LinkImpl(
        boardMap2,
        TransportationMethod.BUS,
        new CoordinateImpl(boardMap, 12, 22),
        new CoordinateImpl(boardMap, 12, 22)
    ));
  }

  @Test//TODO add description here
  public final void testToString(){
    Assert.assertEquals(link.toString(),
        "Board Map : [Palmerston North]\n\tLink : (BUS)\n\t\t"+
        "{Board Map : [Palmerston North] Coordinate <Latitude=10.0 , Longtitude=20.0>} , {Board Map : [Palmerston North] Coordinate <Latitude=12.0 , Longtitude=22.0>}"
    );
  }

}
TOP

Related Classes of org.scotlandyard.tests.engine.boardmap.LinkTest

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.