@Test
public void testAddRoadSegment() throws Exception {

	try {
		this.network.addRoadSegment(null);
		fail("an exception must be throwned when a null road segment is added into a network"); //$NON-NLS-1$
	}
	catch(RoadNetworkException exception) {
		// Expected behavior
	}
	// Try to add a segment that has approximatively the coordinates as
	// an existing segment
	RoadSegmentStub segment3bis = new RoadSegmentStub("segment3bis",100.0001,7.,-100.,-300.); //$NON-NLS-1$
	this.network.addRoadSegment(segment3bis);
	// Must do nothing because the segment is already in the road segment.
	this.network.addRoadSegment(this.segment4);
	// Check the network segment list
	assertEquals(9, this.network.getSegmentCount());
	Collection<RoadSegmentStub> expectedList = new ArrayList<>();
	Collections.addAll(expectedList,
			this.segment1, this.segment2, this.segment3, this.segment4, this.segment5,
			this.segment6, this.segment7, this.segment8, this.segment9);
	for(RoadSegment segment : this.network) {
		assertTrue(expectedList.contains(segment));
		expectedList.remove(segment);
	}
	assertTrue(expectedList.isEmpty());
	Collections.addAll(expectedList,
			this.segment1, this.segment2, this.segment3, this.segment4, this.segment5,
			this.segment6, this.segment7, this.segment8, this.segment9);
	for(RoadSegment segment : this.network.getRoadSegments()) {
		assertTrue(expectedList.contains(segment));
		expectedList.remove(segment);
	}
	assertTrue(expectedList.isEmpty());
	// Check the network connections
	// -100;-300	=> segment3,segment4
	// 0;0			=> segment1,segment4
	// 0;10			=> segment5
	// 100;7		=> segment2,segment3,segment5
	// 100;100		=> segment1,segment2
	assertEquals(this.segment1.getFirstPoint(),this.segment4.getLastPoint());
	assertEquals(this.segment1.getLastPoint(),this.segment2.getLastPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment8.getLastPoint());
	assertEquals(this.segment2.getFirstPoint(),this.segment9.getLastPoint());
	assertEquals(this.segment2.getLastPoint(),this.segment1.getLastPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment8.getLastPoint());
	assertEquals(this.segment3.getFirstPoint(),this.segment9.getLastPoint());
	assertEquals(this.segment3.getLastPoint(),this.segment4.getFirstPoint());
	assertEquals(this.segment4.getFirstPoint(),this.segment3.getLastPoint());
	assertEquals(this.segment4.getLastPoint(),this.segment1.getFirstPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment8.getLastPoint());
	assertEquals(this.segment5.getFirstPoint(),this.segment9.getLastPoint());
	assertEquals(new Point2d(0.,10.), this.segment5.getLastPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment8.getLastPoint());
	assertEquals(this.segment6.getFirstPoint(),this.segment9.getLastPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment8.getLastPoint());
	assertEquals(this.segment6.getLastPoint(),this.segment9.getLastPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment8.getLastPoint());
	assertEquals(this.segment7.getFirstPoint(),this.segment9.getLastPoint());
	assertEquals(new Point2d(100.,-10.), this.segment7.getLastPoint());
	assertEquals(new Point2d(170.,7.), this.segment8.getFirstPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment8.getLastPoint(),this.segment9.getLastPoint());
	assertEquals(new Point2d(120.,100.), this.segment9.getFirstPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment2.getFirstPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment3.getFirstPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment5.getFirstPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment6.getFirstPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment6.getLastPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment7.getFirstPoint());
	assertEquals(this.segment9.getLastPoint(),this.segment8.getLastPoint());
}