source: TraumaOntologies/src/test/java/tudelft/healthpsychology/traumaontologies/answerstate/ListOfAnswersStateTest.java

Last change on this file was 5, checked in by Bart Vastenhouw, 5 years ago

Intermediate update

File size: 2.5 KB
Line 
1package tudelft.healthpsychology.traumaontologies.answerstate;
2
3import static org.junit.Assert.assertEquals;
4import static org.mockito.Matchers.anyString;
5import static org.mockito.Matchers.eq;
6import static org.mockito.Mockito.mock;
7import static org.mockito.Mockito.times;
8import static org.mockito.Mockito.verify;
9import static org.mockito.Mockito.when;
10
11import java.util.Arrays;
12import java.util.Collection;
13import java.util.Collections;
14
15import org.junit.Test;
16
17import tudelft.healthpsychology.traumaontologies.questiontypes.TypedQuestion;
18import tudelft.utilities.tree.Tree;
19
20public 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}
Note: See TracBrowser for help on using the repository browser.