package dcll.dwarf.parseurDwarf;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

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

import dcll.dwarf.parseurDwarf.impl.wiki.WikiQuestionService;

public class MainTest {
	
	private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
	private Main main;

	@Before
	public void setUp() {
	    System.setOut(new PrintStream(outContent));
	}

	@Test
	public void testDisplayQuestion() {
    	WikiQuestionService wiki = new WikiQuestionService();
    	String questionWikiSingleChoice="{Basic Wiki Question\n|type=\"()\"}\n+ The correct answer.\n- Distractor.\n- Distractor.\n- Distractor.";
    	try {
			Question question = wiki.getQuestionFromWikiText(questionWikiSingleChoice);
			Main.displayQuestion(question);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (QuizReaderException e) {
			e.printStackTrace();
		}
    	assertEquals("Question title: Basic Wiki Question\n"
    			+ "Question type: ExclusiveChoice\n"
    			+ "Answer 0: The correct answer. - Credit: 100.0\n"
    			+ "Answer 1: Distractor. - Credit: -100.0\n"
    			+ "Answer 2: Distractor. - Credit: -100.0\n"
    			+ "Answer 3: Distractor. - Credit: -100.0\n"
    			+ "\n\n", outContent.toString());
	}
	
	@Test
	public void testMain(){
		main = new Main();
		assertNotEquals(null,main);
		try {
			Main.main(null);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (QuizReaderException e) {
			e.printStackTrace();
		}
		assertEquals(
		"Test Single choice question\n\n"
		+ "Question title: Basic Wiki Question\n"
		+ "Question type: ExclusiveChoice\n"
		+ "Answer 0: The correct answer. - Credit: 100.0\n"
		+ "Answer 1: Distractor. - Credit: -100.0\n"
		+ "Answer 2: Distractor. - Credit: -100.0\n"
		+ "Answer 3: Distractor. - Credit: -100.0\n"
		+ "\n\n"
		+ "Test Multiple choice question\n\n"
		+ "Question title: Question\n"
		+ "Question type: MultipleChoice\n"
		+ "Answer 0: Correct answer. - Credit: 50.0\n"
		+ "Answer 1: Incorrect answer. - Credit: -100.0\n"
		+ "Answer 2: Correct answer. - Credit: 50.0\n"
		+ "Answer 3: Incorrect answer. - Credit: -100.0\n"
		+ "\n\n"
		+ "Test Quiz\n\n"
		+ "Question title: Basic Wiki Question\n"
		+ "Question type: ExclusiveChoice\n"
		+ "Answer 0: The correct answer. - Credit: 100.0\n"
		+ "Answer 1: Distractor. - Credit: -100.0\n"
		+ "Answer 2: Distractor. - Credit: -100.0\n"
		+ "Answer 3: Distractor. - Credit: -100.0\n"
		+ "\n\n",outContent.toString());
	}
}
