package bwyap.familyfeud.test;

import java.io.File;

import org.json.simple.JSONObject;

import bwyap.familyfeud.FamilyFeud;
import bwyap.familyfeud.FamilyFeudController;
import bwyap.familyfeud.game.state.FFStateType;
import bwyap.familyfeud.game.state.StateAddFamily;
import bwyap.familyfeud.game.state.StateLoadQuestions;
import bwyap.familyfeud.res.JSONQuestionSet;
import bwyap.utility.resource.JSONLoader;

/**
 * Test Driver to test FamilyFeud application
 * @author bwyap
 *
 */
public class FamilyFeudTestDriver {
	
	public static final boolean DEBUG_LOG_CONSOLE = true;
	public static final boolean LOG_VERIFY = true;
	
	private FamilyFeudController app;

	/**
	 * Run the test driver
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("-----------------------");
		System.out.println("! Running test driver !");
		System.out.println("-----------------------");
		
		FamilyFeud.init();
		FamilyFeudTestDriver driver = new FamilyFeudTestDriver(FamilyFeud.app);
		
		// TESTS
		driver.testInit();
		driver.testStart();
		driver.testAddFamilies();
		driver.testLoadQuestions();
		driver.testInitGame();
		driver.testPlayGame();
	}
	
	
	// ==================
	//    TEST METHODS   
	// ==================
	
	/**
	 * Create a new test driver with the given FamilyFeudController app
	 * @param app
	 */
	public FamilyFeudTestDriver(FamilyFeudController app) {
		this.app = app;
	}
	
	/**
	 * Test starting the application
	 */
	public void testStart() {
		app.start();
		app.getGame().changeState(FFStateType.NEW_GAME);
	}
	
	/**
	 * Test initializing the application
	 */
	public void testInit() {
		app.init();
	}
	
	/**
	 * Test adding families to the game
	 */
	public void testAddFamilies() {
		app.getGame().changeState(FFStateType.ADD_FAMILY);
		
		// Add families
		app.getGame().getState().executeAction(StateAddFamily.ACTION_ADDFAMILY, new Object[]{"Tran"});
		app.getGame().getState().executeAction(StateAddFamily.ACTION_ADDFAMILY, new Object[]{"Lee"});
		
		// Finish adding families
		app.getGame().changeState(FFStateType.NEW_GAME);
		
		// Verify that families are added to the game
		if (LOG_VERIFY) System.out.println("### VERIFY > Families: " + app.getGame().getFamilies());
	}
	
	/**
	 * Test the loading of a question set from a JSON file
	 */
	public void testLoadQuestions() {
		File questionFile = new File("res/questionset.json");
		JSONObject o = JSONLoader.loadJSON(questionFile);
		JSONQuestionSet q = new JSONQuestionSet(o);
		
		app.getGame().changeState(FFStateType.LOAD_QUESTIONS);

		app.getGame().getState().executeAction(StateLoadQuestions.ACTION_LOADQUESTIONSET, new Object[]{q});
		
		// Finish adding questions
		app.getGame().changeState(FFStateType.NEW_GAME);

		// Verify that questions were added to the game
		if (LOG_VERIFY) System.out.println("### VERIFY > Questions: " + app.getGame().getQuestions());
	}
	
	/**
	 * Test initialize the game
	 */
	public void testInitGame() {
		app.getGame().changeState(FFStateType.INITIALIZE_GAME);
	}
	
	/**
	 * Test starting the family feud game
	 */
	public void testPlayGame() {
		app.getGame().changeState(FFStateType.PLAY);
	}
	
}

@@ -1336,21 +1336,24 @@
 %0A%09 */%0A%09p
-ublic
+rotected
  FamilyF
@@ -1455,37 +1455,40 @@
 lication%0A%09 */%0A%09p
-ublic
+rotected
  void testStart(
@@ -1604,37 +1604,40 @@
 lication%0A%09 */%0A%09p
-ublic
+rotected
  void testInit()
@@ -1699,37 +1699,40 @@
 the game%0A%09 */%0A%09p
-ublic
+rotected
  void testAddFam
@@ -2301,37 +2301,40 @@
 SON file%0A%09 */%0A%09p
-ublic
+rotected
  void testLoadQu
@@ -2931,37 +2931,40 @@
 the game%0A%09 */%0A%09p
-ublic
+rotected
  void testInitGa
@@ -3084,21 +3084,24 @@
 %0A%09 */%0A%09p
-ublic
+rotected
  void te

Change visibility of methods in test driver to protected