1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.ui; |
---|
16 | |
---|
17 | import static org.junit.Assert.*; |
---|
18 | import static org.mockito.Mockito.mock; |
---|
19 | |
---|
20 | import java.util.Collection; |
---|
21 | import java.util.LinkedList; |
---|
22 | import java.util.List; |
---|
23 | import java.util.logging.Level; |
---|
24 | |
---|
25 | import org.junit.Before; |
---|
26 | import org.junit.Test; |
---|
27 | |
---|
28 | import de.ugoe.cs.autoquest.commands.sequences.CMDsplitSequences; |
---|
29 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
30 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
31 | import de.ugoe.cs.autoquest.test.CommandRunner; |
---|
32 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
33 | import de.ugoe.cs.util.console.TextConsole; |
---|
34 | |
---|
35 | /** |
---|
36 | * |
---|
37 | * @author Patrick Harms |
---|
38 | */ |
---|
39 | public class CMDsplitSequencesTest { |
---|
40 | |
---|
41 | /** |
---|
42 | * |
---|
43 | */ |
---|
44 | @Before |
---|
45 | public void setUp() { |
---|
46 | new TextConsole(Level.FINEST); |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * |
---|
51 | */ |
---|
52 | @SuppressWarnings("unchecked") |
---|
53 | @Test |
---|
54 | public void test() { |
---|
55 | String sequencesName = "sequences"; |
---|
56 | IEventType type = mock(IEventType.class); |
---|
57 | |
---|
58 | Collection<List<Event>> sequences = new LinkedList<List<Event>>(); |
---|
59 | |
---|
60 | for (int i = 0; i < 5; i++) { |
---|
61 | List<Event> sequence = new LinkedList<Event>(); |
---|
62 | |
---|
63 | for (int j = 0; j < 10; j++) { |
---|
64 | Event event = new Event(type); |
---|
65 | event.setTimestamp(((i + 1) * 50) + (j * 10)); |
---|
66 | sequence.add(event); |
---|
67 | } |
---|
68 | |
---|
69 | sequences.add(sequence); |
---|
70 | } |
---|
71 | |
---|
72 | GlobalDataContainer.getInstance().addData(sequencesName, sequences); |
---|
73 | CommandRunner.runCommand(CMDsplitSequences.class, "5", sequencesName); |
---|
74 | |
---|
75 | Object result = GlobalDataContainer.getInstance().getData(sequencesName); |
---|
76 | |
---|
77 | assertNotNull(result); |
---|
78 | assertTrue(result instanceof Collection<?>); |
---|
79 | |
---|
80 | sequences = (Collection<List<Event>>) result; |
---|
81 | |
---|
82 | assertEquals(50, sequences.size()); |
---|
83 | |
---|
84 | for (List<Event> sequence : sequences) { |
---|
85 | assertNotNull(sequence); |
---|
86 | assertEquals(1, sequence.size()); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | } |
---|