package com.masabi.routefinder;
import java.util.Collection;
import java.util.LinkedHashMap;
import junit.framework.Assert;
import org.junit.Test;
import com.masabi.routefinder.BadStationInputException;
import com.masabi.routefinder.Connection;
import com.masabi.routefinder.RouteFinder;
import com.masabi.routefinder.Station;
public class RouteFinderTest {
private RouteFinder routeFinder = new RouteFinder();
@Test(expected = BadStationInputException.class)
public void findRouteWithUnkownFromStation() throws BadStationInputException {
routeFinder.findRoute("Blah!", "A");
}
@Test(expected = BadStationInputException.class)
public void findRouteWithUnkownToStation() throws BadStationInputException {
routeFinder.findRoute("A", "Blah!");
}
@Test(expected = BadStationInputException.class)
public void findRouteWithSameFromAndToStation() throws BadStationInputException {
routeFinder.findRoute("A", "A");
}
@Test
public void findRouteBetweenTwoUnconnectedStations() throws BadStationInputException {
LinkedHashMap<Station, Connection> route = routeFinder.findRoute("A", "B");
Assert.assertNull(route);
}
@Test
public void findRouteBetweenTwoConnectedStations() throws BadStationInputException {
int numConnectionsExpected = 3;
LinkedHashMap<Station, Connection> route = routeFinder.findRoute("A", "H");
Collection<Connection> values = route.values();
Assert.assertNotNull(route);
Assert.assertEquals(route.size(), numConnectionsExpected);
Connection[] connections = values.toArray(new Connection[numConnectionsExpected]);
Assert.assertEquals(connections[0].getStationFrom(), new Station("A"));
Assert.assertEquals(connections[0].getStationTo(), new Station("G"));
Assert.assertEquals(connections[1].getStationFrom(), new Station("G"));
Assert.assertEquals(connections[1].getStationTo(), new Station("F"));
Assert.assertEquals(connections[2].getStationFrom(), new Station("F"));
Assert.assertEquals(connections[2].getStationTo(), new Station("H"));
}
}