package risk;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TerritoryTest {
	Territory territory;
	String name = "testTerritory";
	

	@Before
	public void setUp() throws Exception {
		territory = new Territory(name);
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testGenericTerritory() throws Exception {
		List<Territory> newList = new ArrayList<>();
		assertEquals(name,  territory.getName());
		assertEquals(newList,  territory.getConnections());
		assertEquals(BoardUtils.Colors.NONE, territory.getFaction());
		assertEquals(0, territory.getTroops());
	}
	
	@Test
	public void testGettersandSetters() throws Exception {
		Territory terra2 = new Territory("terra2");
		int numTroops = 42;
		territory.setTroops(numTroops);
		territory.setFaction(BoardUtils.Colors.BLUE);
		territory.addConnection(terra2);
		
		assertEquals(numTroops, territory.getTroops());
		assertEquals(BoardUtils.Colors.BLUE, territory.getFaction());
		assertEquals(1, territory.getConnections().size());
		assertEquals("terra2", territory.getConnections().get(0).getName());
	}
	
	//TODO: re-implement when toString is fixed 
//	@Test
//	public void testToString() throws Exception {
//		Territory terra2 = new Territory("terra2");
//		int numTroops = 42;
//		territory.setTroops(numTroops);
//		territory.setFaction(BoardUtils.Colors.BLUE);
//		territory.addConnection(terra2);
//		
//		String expected = "name=testTerritory\n"
//				+ "faction=BLUE\n"
//				+ "troops=42\n"
//				+ "connections=[name=terra2\n"
//				+ "faction=NONE\n"
//				+ "troops=0\n"
//				+ "connections=[]]";
//		
//		assertEquals(expected, territory.toString());
//	}
	
	//TODO: add JUnit extension to test hashcode and equals
	@Test
	public void testEquals() throws Exception {
		Territory terra2 = new Territory(name);
		assertEquals(terra2, territory);
		
		terra2.setTroops(4);
		assertNotEquals(terra2, territory);
		assertEquals(terra2, terra2);
	}

}

@@ -1262,65 +1262,16 @@
 %0A%09%0D%0A
-%09//TODO: re-implement when toString is fixed %0D%0A//
 %09@Test%0D%0A
 //%09p
@@ -1266,18 +1266,16 @@
 %09@Test%0D%0A
-//
 %09public 
@@ -1314,16 +1314,64 @@
 tion %7B%0D%0A
+%09%09//TODO: re-implement when toString is fixed %0D%0A
 //%09%09Terr
@@ -1777,24 +1777,62 @@
 =%5B%5D%5D%22;%0D%0A
-//
 %09%09%0D%0A
-//
+%09%09String expected = %22testTerritory%22;%0D%0A%09%09%0D%0A
 %09%09assert
@@ -1872,18 +1872,16 @@
 ng());%0D%0A
-//
 %09%7D%0D%0A%09%0D%0A%09

add basic toString test