[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;
|
---|
[338] | 16 |
|
---|
| 17 |
|
---|
[548] | 18 | import java.util.LinkedList;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
[338] | 21 | import org.junit.*;
|
---|
| 22 |
|
---|
[922] | 23 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.IEventTarget;
|
---|
| 25 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
| 26 | import de.ugoe.cs.autoquest.eventcore.IReplayable;
|
---|
[432] | 27 |
|
---|
[338] | 28 | import static org.junit.Assert.*;
|
---|
[547] | 29 | import static org.mockito.Mockito.*;
|
---|
[338] | 30 |
|
---|
| 31 | /**
|
---|
[547] | 32 | * The class <code>EventTest</code> contains tests for the class <code>{@link Event}</code>.
|
---|
[338] | 33 | *
|
---|
| 34 | * @author Steffen Herbold
|
---|
| 35 | * @version 1.0
|
---|
| 36 | */
|
---|
| 37 | public class EventTest {
|
---|
| 38 |
|
---|
[547] | 39 | @Test
|
---|
| 40 | public void testEvent_1() throws Exception {
|
---|
| 41 | Event result = new Event(mock(IEventType.class));
|
---|
[338] | 42 |
|
---|
[547] | 43 | assertNotNull(result);
|
---|
| 44 | }
|
---|
[338] | 45 |
|
---|
[766] | 46 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
[547] | 47 | public void testEvent_2() throws Exception {
|
---|
| 48 | new Event(null);
|
---|
| 49 | }
|
---|
[338] | 50 |
|
---|
[547] | 51 | /*
|
---|
| 52 | @Test
|
---|
| 53 | public void testEquals_1() throws Exception {
|
---|
| 54 | IEventType type1 = mock(IEventType.class);
|
---|
| 55 | IEventType type2 = mock(IEventType.class);
|
---|
| 56 | // when(type1.equals(type2)).thenReturn(true);
|
---|
| 57 | Event fixture = new Event(type1);
|
---|
| 58 | Event other = new Event(type2);
|
---|
[338] | 59 |
|
---|
[547] | 60 | boolean result = fixture.equals(other);
|
---|
[338] | 61 |
|
---|
[547] | 62 | assertTrue(result);
|
---|
| 63 | }
|
---|
[338] | 64 |
|
---|
[547] | 65 | @Test
|
---|
| 66 | public void testEquals_2() throws Exception {
|
---|
| 67 | String type1 = "typeString1";
|
---|
| 68 | String type2 = "typeString2";
|
---|
| 69 | Event fixture = new Event(type1);
|
---|
| 70 | Event other = new Event(type2);
|
---|
[338] | 71 |
|
---|
[547] | 72 | boolean result = fixture.equals(other);
|
---|
[338] | 73 |
|
---|
[547] | 74 | assertFalse(result);
|
---|
| 75 | }
|
---|
[338] | 76 |
|
---|
[547] | 77 | @Test
|
---|
| 78 | public void testEquals_3() throws Exception {
|
---|
| 79 | String type1 = "typeString";
|
---|
| 80 | String type2 = "typeString";
|
---|
| 81 | String target1 = "target";
|
---|
| 82 | String target2 = "target";
|
---|
| 83 | Event fixture = new Event(type1);
|
---|
| 84 | fixture.target = target1;
|
---|
| 85 | Event other = new Event(type2);
|
---|
| 86 | other.target = target2;
|
---|
[338] | 87 |
|
---|
[547] | 88 | boolean result = fixture.equals(other);
|
---|
[338] | 89 |
|
---|
[547] | 90 | assertTrue(result);
|
---|
| 91 | }
|
---|
[338] | 92 |
|
---|
[547] | 93 | @Test
|
---|
| 94 | public void testEquals_4() throws Exception {
|
---|
| 95 | String type1 = "typeString1";
|
---|
| 96 | String type2 = "typeString2";
|
---|
| 97 | String target1 = "target";
|
---|
| 98 | String target2 = "target";
|
---|
| 99 | Event fixture = new Event(type1);
|
---|
| 100 | fixture.target = target1;
|
---|
| 101 | Event other = new Event(type2);
|
---|
| 102 | other.target = target2;
|
---|
[338] | 103 |
|
---|
[547] | 104 | boolean result = fixture.equals(other);
|
---|
[338] | 105 |
|
---|
[547] | 106 | assertFalse(result);
|
---|
| 107 | }
|
---|
[338] | 108 |
|
---|
[547] | 109 | @Test
|
---|
| 110 | public void testEquals_5() throws Exception {
|
---|
| 111 | String type1 = "typeString";
|
---|
| 112 | String type2 = "typeString";
|
---|
| 113 | String target1 = "target1";
|
---|
| 114 | String target2 = "target2";
|
---|
| 115 | Event fixture = new Event(type1);
|
---|
| 116 | fixture.target = target1;
|
---|
| 117 | Event other = new Event(type2);
|
---|
| 118 | other.target = target2;
|
---|
[338] | 119 |
|
---|
[547] | 120 | boolean result = fixture.equals(other);
|
---|
[338] | 121 |
|
---|
[547] | 122 | assertFalse(result);
|
---|
| 123 | }
|
---|
[338] | 124 |
|
---|
[547] | 125 | @Test
|
---|
| 126 | public void testEquals_6() throws Exception {
|
---|
| 127 | String type = "typeString";
|
---|
| 128 | Event fixture = new Event(type);
|
---|
[338] | 129 |
|
---|
[547] | 130 | boolean result = fixture.equals(fixture);
|
---|
[338] | 131 |
|
---|
[547] | 132 | assertTrue(result);
|
---|
| 133 | }
|
---|
[338] | 134 |
|
---|
[547] | 135 | @Test
|
---|
| 136 | public void testEqualsContract() throws Exception {
|
---|
| 137 | EqualsVerifier.forClass(Event.class).suppress(Warning.NONFINAL_FIELDS)
|
---|
| 138 | .withRedefinedSubclass(ReplayableEvent.class).verify();
|
---|
| 139 | }
|
---|
| 140 | */
|
---|
[338] | 141 |
|
---|
[547] | 142 | @Test
|
---|
| 143 | public void testGetTarget_1() throws Exception {
|
---|
| 144 | IEventType type = mock(IEventType.class);
|
---|
| 145 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 146 |
|
---|
| 147 | Event fixture = new Event(type);
|
---|
| 148 | fixture.setTarget(target);
|
---|
[338] | 149 |
|
---|
[547] | 150 | IEventTarget result = fixture.getTarget();
|
---|
[338] | 151 |
|
---|
[547] | 152 | assertSame(target, result);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
[338] | 156 |
|
---|
[547] | 157 | @Test
|
---|
| 158 | public void testGetTarget_2() throws Exception {
|
---|
| 159 | IEventType type = mock(IEventType.class);
|
---|
| 160 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 161 |
|
---|
| 162 | Event fixture = new Event(type, target);
|
---|
[338] | 163 |
|
---|
[547] | 164 | IEventTarget result = fixture.getTarget();
|
---|
[338] | 165 |
|
---|
[547] | 166 | assertSame(target, result);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | @Test
|
---|
| 170 | public void testGetTarget_3() throws Exception {
|
---|
| 171 | IEventType type = mock(IEventType.class);
|
---|
| 172 |
|
---|
| 173 | Event fixture = new Event(type);
|
---|
[338] | 174 |
|
---|
[547] | 175 | IEventTarget result = fixture.getTarget();
|
---|
[338] | 176 |
|
---|
[547] | 177 | assertNull(result);
|
---|
| 178 | }
|
---|
[338] | 179 |
|
---|
[547] | 180 | @Test
|
---|
| 181 | public void testGetType_1() throws Exception {
|
---|
| 182 | IEventType type = mock(IEventType.class);
|
---|
| 183 |
|
---|
| 184 | Event fixture = new Event(type);
|
---|
[338] | 185 |
|
---|
[547] | 186 | IEventType result = fixture.getType();
|
---|
[338] | 187 |
|
---|
[547] | 188 | assertEquals(type, result);
|
---|
| 189 | }
|
---|
[338] | 190 |
|
---|
[547] | 191 | @Test
|
---|
| 192 | public void testSetTarget_1() throws Exception {
|
---|
| 193 | IEventType type = mock(IEventType.class);
|
---|
| 194 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 195 |
|
---|
| 196 | Event fixture = new Event(type);
|
---|
[338] | 197 |
|
---|
[547] | 198 | boolean result = fixture.setTarget(target);
|
---|
[338] | 199 |
|
---|
[547] | 200 | assertTrue(result);
|
---|
| 201 | assertEquals(target, fixture.getTarget());
|
---|
| 202 | }
|
---|
[338] | 203 |
|
---|
[547] | 204 | @Test
|
---|
| 205 | public void testSetTarget_2() throws Exception {
|
---|
| 206 | IEventType type = mock(IEventType.class);
|
---|
| 207 | IEventTarget target1 = mock(IEventTarget.class);
|
---|
| 208 | IEventTarget target2 = mock(IEventTarget.class);
|
---|
| 209 |
|
---|
| 210 | Event fixture = new Event(type);
|
---|
[338] | 211 |
|
---|
[547] | 212 | fixture.setTarget(target1);
|
---|
| 213 | boolean result = fixture.setTarget(target2);
|
---|
| 214 |
|
---|
| 215 | assertFalse(result);
|
---|
[958] | 216 | assertEquals(target1, fixture.getTarget());
|
---|
[547] | 217 | }
|
---|
| 218 |
|
---|
| 219 | @Test
|
---|
| 220 | public void testSetTarget_3() throws Exception {
|
---|
| 221 | IEventType type = mock(IEventType.class);
|
---|
| 222 | IEventTarget target1 = mock(IEventTarget.class);
|
---|
| 223 | IEventTarget target2 = mock(IEventTarget.class);
|
---|
| 224 |
|
---|
| 225 | Event fixture = new Event(type, target1);
|
---|
[338] | 226 |
|
---|
[547] | 227 | boolean result = fixture.setTarget(target2);
|
---|
| 228 |
|
---|
| 229 | assertFalse(result);
|
---|
[958] | 230 | assertEquals(target1, fixture.getTarget());
|
---|
[547] | 231 | }
|
---|
[338] | 232 |
|
---|
[547] | 233 | @Test
|
---|
[771] | 234 | public void testGetId_1() throws Exception {
|
---|
[547] | 235 | IEventType type = mock(IEventType.class);
|
---|
| 236 | when(type.toString()).thenReturn("typeString");
|
---|
| 237 | IEventTarget target = mock(IEventTarget.class);
|
---|
[771] | 238 | when(target.getStringIdentifier()).thenReturn("targetString");
|
---|
[547] | 239 |
|
---|
| 240 | Event fixture = new Event(type, target);
|
---|
[338] | 241 |
|
---|
[547] | 242 | String result = fixture.toString();
|
---|
[338] | 243 |
|
---|
[568] | 244 | assertEquals("typeString.targetString", result);
|
---|
[547] | 245 | }
|
---|
[548] | 246 |
|
---|
| 247 | @Test
|
---|
[771] | 248 | public void testGetId_2() throws Exception {
|
---|
[568] | 249 | IEventType type = mock(IEventType.class);
|
---|
| 250 | when(type.toString()).thenReturn("typeString");
|
---|
| 251 |
|
---|
| 252 | Event fixture = new Event(type);
|
---|
| 253 |
|
---|
| 254 | String result = fixture.toString();
|
---|
| 255 |
|
---|
| 256 | assertEquals("typeString", result);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | @Test
|
---|
[548] | 260 | public void testAddReplayable_1() throws Exception {
|
---|
| 261 | IReplayable replayable = mock(IReplayable.class);
|
---|
[338] | 262 |
|
---|
[548] | 263 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 264 | fixture.addReplayable(replayable);
|
---|
| 265 |
|
---|
| 266 | assertEquals(1, fixture.getReplayables().size());
|
---|
| 267 | assertEquals(replayable, fixture.getReplayables().get(0));
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | @Test
|
---|
| 271 | public void testAddReplayEvent_2() throws Exception {
|
---|
| 272 | IReplayable replayable1 = mock(IReplayable.class);
|
---|
| 273 | IReplayable replayable2 = mock(IReplayable.class);
|
---|
| 274 |
|
---|
| 275 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 276 | fixture.addReplayable(replayable1);
|
---|
| 277 | fixture.addReplayable(replayable2);
|
---|
| 278 |
|
---|
| 279 | assertEquals(2, fixture.getReplayables().size());
|
---|
| 280 | assertEquals(replayable1, fixture.getReplayables().get(0));
|
---|
| 281 | assertEquals(replayable2, fixture.getReplayables().get(1));
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[766] | 284 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
[548] | 285 | public void testAddReplayEvent_fixture_3() throws Exception {
|
---|
| 286 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 287 | fixture.addReplayable(null);
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | @Test
|
---|
| 291 | public void testAddReplaySequence_1() throws Exception {
|
---|
| 292 | IReplayable replayable1 = mock(IReplayable.class);
|
---|
| 293 | IReplayable replayable2 = mock(IReplayable.class);
|
---|
| 294 |
|
---|
| 295 | List<IReplayable> replayableSequences = new LinkedList<IReplayable>();
|
---|
| 296 | replayableSequences.add(replayable1);
|
---|
| 297 | replayableSequences.add(replayable2);
|
---|
| 298 |
|
---|
| 299 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 300 |
|
---|
| 301 | fixture.addReplayableSequence(replayableSequences);
|
---|
| 302 |
|
---|
| 303 | assertEquals(2, fixture.getReplayables().size());
|
---|
| 304 | assertEquals(replayable1, fixture.getReplayables().get(0));
|
---|
| 305 | assertEquals(replayable2, fixture.getReplayables().get(1));
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[766] | 308 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
[548] | 309 | public void testAddReplaySequence_2() throws Exception {
|
---|
| 310 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 311 |
|
---|
| 312 | fixture.addReplayableSequence(null);
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[996] | 315 | @Test
|
---|
| 316 | public void testSetParameter_1() throws Exception {
|
---|
| 317 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 318 | assertNull(fixture.getParameter("key"));
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | @Test
|
---|
| 322 | public void testSetParameter_2() throws Exception {
|
---|
| 323 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 324 | fixture.setParameter("key", "value");
|
---|
| 325 | assertEquals("value", fixture.getParameter("key"));
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | @Test
|
---|
| 329 | public void testSetParameter_3() throws Exception {
|
---|
| 330 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 331 | fixture.setParameter("key", "value");
|
---|
| 332 | fixture.setParameter("key", null);
|
---|
| 333 | assertNull(fixture.getParameter("key"));
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | @Test
|
---|
| 337 | public void testSetParameter_4() throws Exception {
|
---|
| 338 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 339 | fixture.setParameter("key", "value");
|
---|
| 340 | assertNull(fixture.getParameter("key2"));
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
| 344 | public void testSetParameter_5() throws Exception {
|
---|
| 345 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 346 | fixture.setParameter(null, null);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
| 350 | public void testGetParameter_1() throws Exception {
|
---|
| 351 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 352 | fixture.getParameter(null);
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | @Test
|
---|
| 356 | public void testGetTimestamp_1() throws Exception {
|
---|
| 357 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 358 | assertTrue(fixture.getTimestamp() < 0);
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | @Test
|
---|
| 362 | public void testSetTimestamp_1() throws Exception {
|
---|
| 363 | Event fixture = new Event(mock(IEventType.class));
|
---|
| 364 | fixture.setTimestamp(1234);
|
---|
| 365 | assertEquals(1234, fixture.getTimestamp());
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[547] | 368 | public static void main(String[] args) {
|
---|
| 369 | new org.junit.runner.JUnitCore().run(EventTest.class);
|
---|
| 370 | }
|
---|
| 371 | }
|
---|