[927] | 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 | |
---|
[922] | 15 | package de.ugoe.cs.autoquest.eventcore.guimodel; |
---|
[615] | 16 | |
---|
| 17 | import static org.junit.Assert.*; |
---|
| 18 | |
---|
| 19 | import org.junit.Test; |
---|
| 20 | |
---|
[922] | 21 | import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement; |
---|
| 22 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
| 23 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; |
---|
| 24 | |
---|
[615] | 25 | /** |
---|
[1396] | 26 | * |
---|
[615] | 27 | */ |
---|
| 28 | public class AbstractDefaultGUIElementTest { |
---|
| 29 | |
---|
| 30 | /** |
---|
[1396] | 31 | * |
---|
[615] | 32 | */ |
---|
| 33 | @Test |
---|
| 34 | public void testRegisteringEqualGuiElements() { |
---|
| 35 | IGUIElement guiElement1 = new AbstractDefaultGUIElementTestImpl(); |
---|
| 36 | IGUIElement guiElement2 = new AbstractDefaultGUIElementTestImpl(); |
---|
| 37 | |
---|
| 38 | assertCompletelyUnequal(guiElement1, guiElement2); |
---|
| 39 | |
---|
| 40 | guiElement1.addEqualGUIElement(guiElement2); |
---|
| 41 | assertCompletelyEqual(guiElement1, guiElement2); |
---|
| 42 | |
---|
| 43 | IGUIElement guiElement3 = new AbstractDefaultGUIElementTestImpl(); |
---|
| 44 | |
---|
| 45 | assertCompletelyEqual(guiElement1, guiElement2); |
---|
| 46 | assertCompletelyUnequal(guiElement1, guiElement3); |
---|
| 47 | assertCompletelyUnequal(guiElement2, guiElement3); |
---|
| 48 | |
---|
| 49 | guiElement1.addEqualGUIElement(guiElement3); |
---|
| 50 | assertCompletelyEqual(guiElement1, guiElement2, guiElement3); |
---|
| 51 | |
---|
| 52 | IGUIElement guiElement4 = new AbstractDefaultGUIElementTestImpl(); |
---|
| 53 | |
---|
| 54 | assertCompletelyEqual(guiElement1, guiElement2, guiElement3); |
---|
| 55 | assertCompletelyUnequal(guiElement1, guiElement4); |
---|
| 56 | assertCompletelyUnequal(guiElement2, guiElement4); |
---|
| 57 | assertCompletelyUnequal(guiElement3, guiElement4); |
---|
| 58 | |
---|
| 59 | guiElement3.addEqualGUIElement(guiElement4); |
---|
| 60 | assertCompletelyEqual(guiElement1, guiElement2, guiElement3, guiElement4); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
[1396] | 64 | * |
---|
[615] | 65 | */ |
---|
| 66 | private void assertCompletelyUnequal(IGUIElement... guiElements) { |
---|
| 67 | for (int i = 0; i < guiElements.length; i++) { |
---|
| 68 | for (int j = i + 1; j < guiElements.length; j++) { |
---|
| 69 | assertFalse(guiElements[i].equals(guiElements[j])); |
---|
| 70 | assertFalse(guiElements[j].equals(guiElements[i])); |
---|
| 71 | assertNotSame(guiElements[i].hashCode(), guiElements[j].hashCode()); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /** |
---|
[1396] | 77 | * |
---|
[615] | 78 | */ |
---|
| 79 | private void assertCompletelyEqual(IGUIElement... guiElements) { |
---|
| 80 | for (int i = 0; i < guiElements.length; i++) { |
---|
| 81 | for (int j = i; j < guiElements.length; j++) { |
---|
| 82 | assertTrue(guiElements[i].equals(guiElements[j])); |
---|
| 83 | assertTrue(guiElements[j].equals(guiElements[i])); |
---|
| 84 | assertEquals(guiElements[i].hashCode(), guiElements[j].hashCode()); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
[1396] | 90 | * |
---|
[615] | 91 | */ |
---|
| 92 | public class AbstractDefaultGUIElementTestImpl extends AbstractDefaultGUIElement |
---|
| 93 | implements IGUIElement |
---|
| 94 | { |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * |
---|
| 98 | */ |
---|
| 99 | public AbstractDefaultGUIElementTestImpl() { |
---|
| 100 | super(null, null); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /** */ |
---|
| 104 | private static final long serialVersionUID = 1L; |
---|
| 105 | |
---|
| 106 | /* (non-Javadoc) |
---|
[922] | 107 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() |
---|
[615] | 108 | */ |
---|
| 109 | @Override |
---|
| 110 | public String getPlatform() { |
---|
| 111 | return "TEST"; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /* (non-Javadoc) |
---|
[922] | 115 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec) |
---|
[615] | 116 | */ |
---|
| 117 | @Override |
---|
| 118 | public void updateSpecification(IGUIElementSpec furtherSpec) { |
---|
| 119 | throw new UnsupportedOperationException(); |
---|
| 120 | } |
---|
| 121 | |
---|
[681] | 122 | @Override |
---|
| 123 | public String getStringIdentifier() { |
---|
| 124 | return "DUMMY"; |
---|
| 125 | } |
---|
| 126 | |
---|
[615] | 127 | } |
---|
| 128 | |
---|
| 129 | } |
---|