1 | package tudelft.healthpsychology.traumaontologies.answerstate;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.mockito.Matchers.anyString;
|
---|
5 | import static org.mockito.Matchers.eq;
|
---|
6 | import static org.mockito.Mockito.mock;
|
---|
7 | import static org.mockito.Mockito.times;
|
---|
8 | import static org.mockito.Mockito.verify;
|
---|
9 | import static org.mockito.Mockito.when;
|
---|
10 |
|
---|
11 | import java.util.Arrays;
|
---|
12 | import java.util.Collection;
|
---|
13 | import java.util.Collections;
|
---|
14 |
|
---|
15 | import org.junit.Test;
|
---|
16 |
|
---|
17 | import tudelft.healthpsychology.traumaontologies.questiontypes.TypedQuestion;
|
---|
18 | import tudelft.utilities.tree.Tree;
|
---|
19 |
|
---|
20 | public class ListOfAnswersStateTest {
|
---|
21 |
|
---|
22 | private Tree<String, Collection<Property>, OntologyNode> tree = mock(
|
---|
23 | Tree.class);
|
---|
24 |
|
---|
25 | @Test
|
---|
26 | public void smokeTest() {
|
---|
27 | new ListOfAnswersState(Collections.emptyList());
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void testgetOptions() {
|
---|
32 | // we should get options from first AnswerState with non-null options
|
---|
33 | AnswerState state1 = mock(AnswerState.class);
|
---|
34 | AnswerState state2 = mock(AnswerState.class);
|
---|
35 | when(state1.getOptions(tree)).thenReturn(null);
|
---|
36 | TypedQuestion options = mock(TypedQuestion.class);
|
---|
37 | when(state2.getOptions(tree)).thenReturn(options);
|
---|
38 |
|
---|
39 | ListOfAnswersState las = new ListOfAnswersState(
|
---|
40 | Arrays.asList(state1, state2));
|
---|
41 | assertEquals(options, las.getOptions(tree));
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Test
|
---|
46 | public void testgetOptionsFinished() {
|
---|
47 | // we should get options from first AnswerState with non-null options
|
---|
48 | AnswerState state1 = mock(AnswerState.class);
|
---|
49 | when(state1.getOptions(tree)).thenReturn(null);
|
---|
50 |
|
---|
51 | ListOfAnswersState las = new ListOfAnswersState(Arrays.asList(state1));
|
---|
52 | assertEquals(null, las.getOptions(tree));
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Test
|
---|
57 | public void testWith() {
|
---|
58 | // with should be passed to first non-null state
|
---|
59 | AnswerState state1 = mock(AnswerState.class);
|
---|
60 | AnswerState state2 = mock(AnswerState.class);
|
---|
61 | when(state1.getOptions(tree)).thenReturn(null);
|
---|
62 | TypedQuestion options = mock(TypedQuestion.class);
|
---|
63 | when(options.fits(anyString())).thenReturn(true);
|
---|
64 | when(state2.getOptions(tree)).thenReturn(options);
|
---|
65 |
|
---|
66 | ListOfAnswersState las = new ListOfAnswersState(
|
---|
67 | Arrays.asList(state1, state2));
|
---|
68 | las.with("bla", tree);
|
---|
69 | verify(state2, times(1)).with(eq("bla"), eq(tree));
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Test(expected = IllegalStateException.class)
|
---|
73 | public void testWithFinished() {
|
---|
74 | // we can't do with on final state.
|
---|
75 | AnswerState state1 = mock(AnswerState.class);
|
---|
76 | when(state1.getOptions(tree)).thenReturn(null);
|
---|
77 |
|
---|
78 | ListOfAnswersState las = new ListOfAnswersState(Arrays.asList(state1));
|
---|
79 | las.with("bla", tree);
|
---|
80 | }
|
---|
81 |
|
---|
82 | }
|
---|