@Test public void test_question_questionMultiChoice() { // GIVEN Poll sond = new Poll(); Question q = new Question(); q.setType(QuestionType.MULTIPLE_CHOICE); List<Question> lq = new ArrayList<Question>(); lq.add(q); // WHEN sond.setQuestions(lq); // THEN assertNotNull(sond.getQuestions()); assertNotNull(sond.getQuestions().get(0)); assertEquals(sond.getQuestions().get(0).getType(), QuestionType.MULTIPLE_CHOICE); }
@Test public void test_poll_setQuestions_noCampaign() { // GIVEN Poll sond = new Poll(); List<Question> questList = new ArrayList<Question>(); // WHEN sond.setQuestions(questList); // THEN assertEquals(sond.getQuestions(), questList); }
@Test public void test_poll_setQuestions_checkIDs() { // GIVEN Poll sond = new Poll(); Question q1 = new Question(); q1.setId(1); Question q2 = new Question(); q2.setId(2); Question q3 = new Question(); q3.setId(3); List<Question> lqs = new ArrayList<Question>(); lqs.add(q1); lqs.add(q2); lqs.add(q3); // WHEN sond.setQuestions(lqs); // THEN assertEquals(sond.getQuestions().get(0).getId(), 1); assertEquals(sond.getQuestions().get(1).getId(), 2); assertEquals(sond.getQuestions().get(2).getId(), 3); }
public static boolean toCsv(String fullyNamedPath, Poll poll) { StringBuilder sb = new StringBuilder(); sb.append(String.format("Questions;Answer;Votes;WeightedVotes;%n")); for (Question question : poll.getQuestions()) { for (Answer answer : question.getAnswers()) { int votesCount = answer.getVotes().size(); int weightedVotesCount = answer.getVotes().size() * answer.getValue(); String questionTitle = question.getTitle().replace("\"", "\"\""); String answerText = answer.getText().replace("\"", "\"\""); sb.append( String.format( "\"%s\";\"%s\";%s;%s;%n", questionTitle, answerText, votesCount, weightedVotesCount)); } } return write(fullyNamedPath, sb.toString()); }
/* Tests CDR */ @Test public void test_poll_with_ordo_questions() { // GIVEN Poll sond = new Poll(); Question q1 = new Question(); q1.setId(1); q1.setOrderNumber(1); Question q2 = new Question(); q2.setId(2); q2.setOrderNumber(2); List<Question> quests = new ArrayList<Question>(); quests.add(q1); quests.add(q2); // WHEN sond.setQuestions(quests); // THEN assertEquals(sond.getQuestions().get(0).getOrderNumber(), 1); assertEquals(sond.getQuestions().get(1).getOrderNumber(), 2); }