private static final int EXPECTED_NUMBER_OF_QUESTIONS = 2;
/* tests */
public void testReadExamWithDefaultRules() throws Exception {
MultipleChoiceExamXmlParser parser = new MultipleChoiceExamXmlParser();
MultipleChoiceExam exam = parser.parse(getInputStreamForExamWithDefaultRules());
assertEquals(exam.getTitle(), EXPECTED_TITLE);
assertEquals(exam.numberOfQuestions(), EXPECTED_NUMBER_OF_QUESTIONS);
assertEquals(exam.getRules().getClass(), SimpleMultipleChoiceExamRules.class);
assertEquals(((SimpleMultipleChoiceExamRules) exam.getRules()).getPercentageOfCorrectAnswersToPass(),
SimpleMultipleChoiceExamRules.DEFAULT_PERCENTAGE_OF_CORRECT_ANSWERS_TO_PASS);
int questionNumber = 1;
for (MultipleChoiceQuestion question : exam) {
assertEquals("Topic "+ questionNumber, question.getTopic());
assertEquals("question " + questionNumber, question.getQuestion());
assertEquals(3, question.getAnswerOptions().size());
assertEquals("A", question.getAnswerOptions().get(0));
assertEquals("B", question.getAnswerOptions().get(1));
assertEquals("C", question.getAnswerOptions().get(2));
assertEquals(1, question.getCorrectAnswers().size());
assertEquals("Explanation " + questionNumber, question.getExplanation());
questionNumber++;
}
assertTrue(exam.getQuestions().get(0).getCorrectAnswers().contains("A"));
assertTrue(exam.getQuestions().get(1).getCorrectAnswers().contains("C"));
}