1 | package de.ugoe.cs.autoquest.eventcore.guimodel; |
---|
2 | |
---|
3 | import static org.junit.Assert.*; |
---|
4 | |
---|
5 | import org.junit.Test; |
---|
6 | |
---|
7 | /** |
---|
8 | * Test of {@link GUIElementTree} |
---|
9 | * @author Fabian Glaser |
---|
10 | * |
---|
11 | */ |
---|
12 | public class GUIElementTreeTest { |
---|
13 | |
---|
14 | @Test |
---|
15 | public void testAdd() { |
---|
16 | GUIElementTree tree = new GUIElementTree(); |
---|
17 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
18 | tree.add(10l, null, spec); |
---|
19 | |
---|
20 | assertEquals(1, tree.size()); |
---|
21 | } |
---|
22 | |
---|
23 | @Test |
---|
24 | public void testAddWithParent(){ |
---|
25 | GUIElementTree tree = new GUIElementTree(); |
---|
26 | IGUIElementSpec parentspec = new MockGUIElementSpec(); |
---|
27 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
28 | tree.add(10l, null, parentspec); |
---|
29 | tree.add(20l, 10l, spec); |
---|
30 | |
---|
31 | assertEquals(2, tree.size()); |
---|
32 | |
---|
33 | IGUIElement element = tree.find(20l); |
---|
34 | assertEquals(parentspec, element.getParent().getSpecification()); |
---|
35 | } |
---|
36 | |
---|
37 | @Test |
---|
38 | public void testFindExisting() { |
---|
39 | GUIElementTree tree = new GUIElementTree(); |
---|
40 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
41 | tree.add(10l, 0l, spec); |
---|
42 | |
---|
43 | IGUIElement element = tree.find(10l); |
---|
44 | assertNotNull(element); |
---|
45 | } |
---|
46 | |
---|
47 | @Test |
---|
48 | public void testFindNonExisting(){ |
---|
49 | GUIElementTree tree = new GUIElementTree(); |
---|
50 | try{ |
---|
51 | tree.find(10l); |
---|
52 | fail("Exception was not thrown."); |
---|
53 | } |
---|
54 | catch(Exception e){ |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | @Test |
---|
59 | public void testRemoveSingleElement() { |
---|
60 | GUIElementTree tree = new GUIElementTree(); |
---|
61 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
62 | tree.add(10l, null, spec); |
---|
63 | |
---|
64 | assertEquals(1, tree.size()); |
---|
65 | assertEquals(1, tree.remove(10l)); |
---|
66 | } |
---|
67 | |
---|
68 | @Test |
---|
69 | public void testRemoveWithChildElement(){ |
---|
70 | GUIElementTree tree = new GUIElementTree(); |
---|
71 | IGUIElementSpec parentspec = new MockGUIElementSpec(); |
---|
72 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
73 | tree.add(10l, null, parentspec); |
---|
74 | tree.add(20l, 10l, spec); |
---|
75 | |
---|
76 | assertEquals(2, tree.remove(10l)); |
---|
77 | assertEquals(0, tree.size()); |
---|
78 | } |
---|
79 | |
---|
80 | @Test |
---|
81 | public void testRemoveNonExisting(){ |
---|
82 | GUIElementTree tree = new GUIElementTree(); |
---|
83 | assertEquals(0, tree.remove(10l)); |
---|
84 | } |
---|
85 | |
---|
86 | @Test |
---|
87 | public void testGetGUIModel() { |
---|
88 | GUIElementTree tree = new GUIElementTree(); |
---|
89 | assertNotNull(tree.getGUIModel()); |
---|
90 | } |
---|
91 | } |
---|