1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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());
}
}
|