summaryrefslogtreecommitdiff
path: root/tst/com/p4square/grow/model/QuestionTest.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2013-10-20 23:14:51 -0700
committerJesse Morgan <jesse@jesterpm.net>2013-10-20 23:14:51 -0700
commite472550fe154f0afa5b36d2a7e2334d4680d7884 (patch)
tree8131e3fa7db162f9a072ef4d89e7fb25d338cdd4 /tst/com/p4square/grow/model/QuestionTest.java
parent31303114ef03b13ab320ee553f11a73346be7f4a (diff)
First stage of a major refactoring.
Question and Answer can now be serialized and deserialized to/from JSON. As such, I no longer have to pass awkward maps around. As part of this change I have introduced a Provider interface to abstract out loading and persisting these beans. The scoring logic has been completed factored out of SurveyResultsResource and into the various ScoringEngines. Tests have been added for Question, Answer, and the ScoringEngines. A bug has been fixed in computing the value for slider questions. The label identifiers in the circle questions have changed from all lower case to camel case. That is, topleft is now topLeft. Several issues have been corrected in the circle answers where the point values did not match the labels. Testing and code coverage support and reports have been added.
Diffstat (limited to 'tst/com/p4square/grow/model/QuestionTest.java')
-rw-r--r--tst/com/p4square/grow/model/QuestionTest.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/tst/com/p4square/grow/model/QuestionTest.java b/tst/com/p4square/grow/model/QuestionTest.java
new file mode 100644
index 0000000..d09d2d8
--- /dev/null
+++ b/tst/com/p4square/grow/model/QuestionTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for the Question class.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class QuestionTest {
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(QuestionTest.class.getName());
+ }
+
+ /**
+ * Verify that all the getters and setters function.
+ */
+ @Test
+ public void testGetAndSet() {
+ TextQuestion q = new TextQuestion();
+
+ q.setId("123");
+ assertEquals("123", q.getId());
+
+ q.setQuestion("Hello World");
+ assertEquals("Hello World", q.getQuestion());
+
+ q.setPreviousQuestion("122");
+ assertEquals("122", q.getPreviousQuestion());
+
+ q.setNextQuestion("124");
+ assertEquals("124", q.getNextQuestion());
+ }
+
+ /**
+ * Verify the correct next question is returned.
+ */
+ @Test
+ public void testGetNextQuestion() {
+ // Setup the Question
+ TextQuestion q = new TextQuestion();
+ q.setNextQuestion("defaultNext");
+
+ Answer answerWithNext = new Answer();
+ answerWithNext.setNextQuestion("answerNext");
+
+ q.getAnswers().put("withNext", answerWithNext);
+ q.getAnswers().put("withoutNext", new Answer());
+
+ // Answer without a nextQuestion should return default.
+ assertEquals("defaultNext", q.getNextQuestion("withoutNext"));
+
+ // Answer with a nextQuestion should return it's next question.
+ assertEquals("answerNext", q.getNextQuestion("withNext"));
+
+ // Unknown answer should also return the default
+ assertEquals("defaultNext", q.getNextQuestion("unknownAnswer"));
+ }
+
+ /**
+ * Validate the toString() results for the enum.
+ *
+ * This may seem like an odd test, but it is very important for these to be
+ * lowercase to match the values in the JSON files.
+ */
+ @Test
+ public void testToString() {
+ assertEquals("text", Question.QuestionType.TEXT.toString());
+ assertEquals("image", Question.QuestionType.IMAGE.toString());
+ assertEquals("slider", Question.QuestionType.SLIDER.toString());
+ assertEquals("quad", Question.QuestionType.QUAD.toString());
+ assertEquals("circle", Question.QuestionType.CIRCLE.toString());
+ }
+}