[1113] | 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 | |
---|
[1005] | 15 | package de.ugoe.cs.autoquest.eventcore.guimodel; |
---|
| 16 | |
---|
| 17 | import static org.junit.Assert.*; |
---|
| 18 | |
---|
| 19 | import org.junit.Test; |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * Test of {@link GUIElementTree} |
---|
| 23 | * @author Fabian Glaser |
---|
| 24 | * |
---|
| 25 | */ |
---|
| 26 | public class GUIElementTreeTest { |
---|
| 27 | |
---|
[1053] | 28 | @Test |
---|
[1085] | 29 | public void testAdd() throws Exception { |
---|
| 30 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 31 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
| 32 | tree.add(10l, null, spec); |
---|
| 33 | |
---|
| 34 | assertEquals(1, tree.size()); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | @Test |
---|
[1085] | 38 | public void testAddWithParent() throws Exception { |
---|
| 39 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 40 | IGUIElementSpec parentspec = new MockGUIElementSpec(); |
---|
| 41 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
| 42 | tree.add(10l, null, parentspec); |
---|
| 43 | tree.add(20l, 10l, spec); |
---|
| 44 | |
---|
| 45 | assertEquals(2, tree.size()); |
---|
| 46 | |
---|
| 47 | IGUIElement element = tree.find(20l); |
---|
| 48 | assertEquals(parentspec, element.getParent().getSpecification()); |
---|
| 49 | } |
---|
[1005] | 50 | |
---|
[1053] | 51 | @Test |
---|
[1085] | 52 | public void testFindExisting() throws Exception { |
---|
| 53 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 54 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
| 55 | tree.add(10l, 0l, spec); |
---|
| 56 | |
---|
| 57 | IGUIElement element = tree.find(10l); |
---|
| 58 | assertNotNull(element); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | @Test |
---|
[1085] | 62 | public void testFindNonExisting() throws Exception { |
---|
| 63 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 64 | assertEquals(tree.find(10l), null); |
---|
| 65 | } |
---|
[1005] | 66 | |
---|
[1053] | 67 | @Test |
---|
[1085] | 68 | public void testRemoveSingleElement() throws Exception { |
---|
| 69 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 70 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
| 71 | tree.add(10l, null, spec); |
---|
| 72 | |
---|
| 73 | assertEquals(1, tree.size()); |
---|
| 74 | assertEquals(1, tree.remove(10l)); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | @Test |
---|
[1085] | 78 | public void testRemoveWithChildElement() throws Exception { |
---|
| 79 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 80 | IGUIElementSpec parentspec = new MockGUIElementSpec(); |
---|
| 81 | IGUIElementSpec spec = new MockGUIElementSpec(); |
---|
| 82 | tree.add(10l, null, parentspec); |
---|
| 83 | tree.add(20l, 10l, spec); |
---|
| 84 | |
---|
| 85 | assertEquals(2, tree.remove(10l)); |
---|
| 86 | assertEquals(0, tree.size()); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | @Test |
---|
| 90 | public void testRemoveNonExisting(){ |
---|
[1085] | 91 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 92 | assertEquals(0, tree.remove(10l)); |
---|
| 93 | } |
---|
[1005] | 94 | |
---|
[1053] | 95 | @Test |
---|
| 96 | public void testGetGUIModel() { |
---|
[1085] | 97 | GUIElementTree<Long> tree = new GUIElementTree<Long>(); |
---|
[1053] | 98 | assertNotNull(tree.getGUIModel()); |
---|
| 99 | } |
---|
[1005] | 100 | } |
---|