@Test
public void insertQuestionCorrectlyPageObject() throws Exception {
survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\surveyfiles\\insertquestioncorrectly.xml")));
survey.addInsertQuestionListener(this);
Question y = survey.getQuestionByID("Y");
Question z = y.populateTemplate("Z", null, false, "");
survey.insertQuestion(z, survey.pageOf(y.getId()), 2);
checkQuestionInserted(z, 0, 2);
assertEquals(z, survey.getPages().get(0).getQuestions().get(2));
assertEquals(survey.getQuestionByID("X"), survey.getPages().get(0).getQuestions().get(1));
Question a = z.populateTemplate("A", null, false, "");
survey.insertQuestion(a, survey.pageOf(z.getId()), 0);
checkQuestionInserted(a, 0, 0);
assertEquals(a, survey.getPages().get(0).getQuestions().get(0));
assertEquals(y, survey.getPages().get(0).getQuestions().get(1));
Question m = z.populateTemplate("M", null, false, "");
survey.insertQuestion(m, survey.pageOf(z.getId()), 1);
checkQuestionInserted(m, 0, 1);
assertEquals(m, survey.getPages().get(0).getQuestions().get(1));
assertEquals(a, survey.getPages().get(0).getQuestions().get(0));
assertEquals(survey.getQuestionByID("Y"), survey.getPages().get(0).getQuestions().get(2));
//here we insert on a different page
Question c = z.populateTemplate("C", null, false, "");
survey.insertQuestion(c, survey.pageOf(survey.getQuestionByID("J").getId()), 1);
checkQuestionInserted(c, 1, 1);
assertEquals(survey.getQuestionByID("J"), survey.getPages().get(1).getQuestions().get(0));
assertEquals(c, survey.getPages().get(1).getQuestions().get(1));
assertEquals(survey.getQuestionByID("L"), survey.getPages().get(1).getQuestions().get(2));