source: trunk/EventBenchCoreTest/src/de/ugoe/cs/eventbench/data/ReplayableEventTest.java @ 338

Last change on this file since 338 was 338, checked in by sherbold, 13 years ago
  • added JUnit test cases for de.ugoe.cs.eventbench.data.Event and ReplayableEvent?
  • Property svn:mime-type set to text/plain
File size: 18.6 KB
Line 
1package de.ugoe.cs.eventbench.data;
2
3import java.util.LinkedList;
4import java.util.List;
5
6import junitx.framework.ListAssert;
7import de.ugoe.cs.eventbench.IReplayDecorator;
8import nl.jqno.equalsverifier.EqualsVerifier;
9import nl.jqno.equalsverifier.Warning;
10
11import org.junit.*;
12import static org.junit.Assert.*;
13
14/**
15 * The class <code>ReplayableEventTest</code> contains tests for the class
16 * <code>{@link ReplayableEvent}</code>.
17 *
18 * @generatedBy CodePro at 12/20/11 10:17 AM
19 * @author Steffen Herbold
20 * @version 1.0
21 */
22public class ReplayableEventTest {
23
24        private static class MockReplayable implements IReplayable {
25
26                private static final long serialVersionUID = 1L;
27
28                final String replay;
29                final String target;
30
31                public MockReplayable(String replay, String target) {
32                        this.replay = replay;
33                        this.target = target;
34                }
35
36                @Override
37                public String getReplay() {
38                        return replay;
39                }
40
41                @Override
42                public String getTarget() {
43                        return target;
44                }
45
46                @Override
47                public boolean equals(Object other) {
48                        if (this == other) {
49                                return true;
50                        }
51                        if (other instanceof MockReplayable) {
52                                if (replay != null && target != null) {
53                                        return replay.equals(((MockReplayable) other).replay)
54                                                        && target.equals(((MockReplayable) other).target);
55                                } else if (replay != null && target == null) {
56                                        return replay.equals(((MockReplayable) other).replay)
57                                                        && ((MockReplayable) other).target == null;
58                                } else if (replay == null && target != null) {
59                                        return ((MockReplayable) other).replay == null
60                                                        && target.equals(((MockReplayable) other).target);
61                                } else {
62                                        return ((MockReplayable) other).replay == null
63                                                        && ((MockReplayable) other).target == null;
64                                }
65                        }
66                        return false;
67                }
68               
69                @Override
70                public int hashCode() {
71                        int hashCode = 17;
72                        if( replay!=null ) {
73                                hashCode *= replay.hashCode();
74                        }
75                        if( target!=null ) {
76                                hashCode *= target.hashCode();
77                        }
78                        return hashCode;
79                }
80        }
81       
82        private static class StubReplayDecorator implements IReplayDecorator {
83
84                private static final long serialVersionUID = 1L;
85
86                @Override
87                public String getHeader() {
88                        return null;
89                }
90
91                @Override
92                public String getFooter() {
93                        return null;
94                }
95
96                @Override
97                public String getSessionHeader(int sessionId) {
98                        return null;
99                }
100
101                @Override
102                public String getSessionFooter(int sessionId) {
103                        return null;
104                }
105               
106        }
107
108        @Test
109        public void testReplayableEvent_1() throws Exception {
110                String type = "typeString";
111
112                ReplayableEvent<MockReplayable> result = new ReplayableEvent<MockReplayable>(
113                                type);
114
115                assertNotNull(result);
116                assertNotNull(result.replayEvents);
117                assertTrue(result.replayEvents.isEmpty());
118                assertEquals(true, result.replayValid);
119                assertEquals(null, result.decorator);
120        }
121
122        @Test(expected = java.security.InvalidParameterException.class)
123        public void testReplayableEvent_2() throws Exception {
124                new ReplayableEvent<MockReplayable>(null);
125        }
126
127        @Test
128        public void testAddReplayEvent_1() throws Exception {
129                String type = "typeString";
130                String replayableReplay = "replayString";
131                String replaybleTarget = "replayTargetString";
132                MockReplayable replayable = new MockReplayable(replayableReplay,
133                                replaybleTarget);
134                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
135                                type);
136                fixture.addReplayEvent(replayable);
137               
138               
139                assertEquals(1, fixture.replayEvents.size());
140                assertEquals(replayable, fixture.replayEvents.get(0));
141        }
142       
143        @Test
144        public void testAddReplayEvent_2() throws Exception {
145                String type = "typeString";
146                String replayableReplay1 = "replayString1";
147                String replayableReplay2 = "replayString2";
148                String replaybleTarget1 = "replayTargetString1";
149                String replaybleTarget2 = "replayTargetString2";
150                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
151                                replaybleTarget1);
152                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replaybleTarget2);
153                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
154                                type);
155                fixture.addReplayEvent(replayable1);
156                fixture.addReplayEvent(replayable2);
157               
158               
159                assertEquals(2, fixture.replayEvents.size());
160                assertEquals(replayable1, fixture.replayEvents.get(0));
161                assertEquals(replayable2, fixture.replayEvents.get(1));
162        }
163
164        @Test(expected = java.security.InvalidParameterException.class )
165        public void testAddReplayEvent_fixture_3() throws Exception {
166                String type = "typeString";
167                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
168                                type);
169                fixture.addReplayEvent(null);
170        }
171
172        @Test
173        public void testAddReplaySequence_1() throws Exception {
174                String type = "typeString";
175                String replayableReplay1 = "replayString1";
176                String replayableReplay2 = "replayString2";
177                String replaybleTarget1 = "replayTargetString1";
178                String replaybleTarget2 = "replayTargetString2";
179                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
180                                replaybleTarget1);
181                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replaybleTarget2);
182                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
183                replaySequence.add(replayable1);
184                replaySequence.add(replayable2);
185                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
186                                type);
187               
188                fixture.addReplaySequence(replaySequence);             
189               
190                assertEquals(2, fixture.replayEvents.size());
191                assertEquals(replayable1, fixture.replayEvents.get(0));
192                assertEquals(replayable2, fixture.replayEvents.get(1));
193        }
194
195        @Test(expected = java.security.InvalidParameterException.class )
196        public void testAddReplaySequence_2() throws Exception {
197                String type = "typeString";
198                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
199                                type);
200               
201                fixture.addReplaySequence(null);       
202        }
203
204        @Test
205        public void testEquals_1() throws Exception {
206                String type = "typeString";
207                boolean replayValid = true;
208                String replayableReplay1 = "replayString1";
209                String replayableReplay2 = "replayString2";
210                String replayableTarget1 = "replayTargetString1";
211                String replayableTarget2 = "replayTargetString2";
212                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
213                                replayableTarget1);
214                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
215                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
216                replaySequence.add(replayable1);
217                replaySequence.add(replayable2);
218                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
219                                type);
220                fixture.replayEvents = replaySequence;
221                fixture.replayValid = replayValid;
222               
223                String typeOther = "typeString";
224                boolean replayValidOther = true;
225                String replayableReplayOther1 = "replayString1";
226                String replayableReplayOther2 = "replayString2";
227                String replaybleTargetOther1 = "replayTargetString1";
228                String replaybleTargetOther2 = "replayTargetString2";
229                MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
230                                replaybleTargetOther1);
231                MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
232                List<MockReplayable> replaySequenceOther = new LinkedList<MockReplayable>();
233                replaySequenceOther.add(replayableOther1);
234                replaySequenceOther.add(replayableOther2);
235                ReplayableEvent<MockReplayable> other = new ReplayableEvent<MockReplayable>(
236                                typeOther);
237                other.replayEvents = replaySequenceOther;
238                other.replayValid = replayValidOther;
239
240                boolean result = fixture.equals(other);
241
242                assertEquals(true, result);
243        }
244       
245        @Test
246        public void testEquals_2() throws Exception {
247                String type = "typeString";
248                boolean replayValid = true;
249                String replayableReplay1 = "replayString1";
250                String replayableReplay2 = "replayString2";
251                String replayableTarget1 = "replayTargetString1";
252                String replayableTarget2 = "replayTargetString2";
253                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
254                                replayableTarget1);
255                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
256                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
257                replaySequence.add(replayable1);
258                replaySequence.add(replayable2);
259                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
260                                type);
261                fixture.replayEvents = replaySequence;
262                fixture.replayValid = replayValid;
263               
264                String typeOther = "typeString2";
265                boolean replayValidOther = true;
266                String replayableReplayOther1 = "replayString1";
267                String replayableReplayOther2 = "replayString2";
268                String replaybleTargetOther1 = "replayTargetString1";
269                String replaybleTargetOther2 = "replayTargetString2";
270                MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
271                                replaybleTargetOther1);
272                MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
273                List<MockReplayable> replaySequenceOther = new LinkedList<MockReplayable>();
274                replaySequenceOther.add(replayableOther1);
275                replaySequenceOther.add(replayableOther2);
276                ReplayableEvent<MockReplayable> other = new ReplayableEvent<MockReplayable>(
277                                typeOther);
278                other.replayEvents = replaySequenceOther;
279                other.replayValid = replayValidOther;
280
281                boolean result = fixture.equals(other);
282
283                assertEquals(false, result);
284        }
285       
286        @Test
287        public void testEquals_3() throws Exception {
288                String type = "typeString";
289                boolean replayValid = true;
290                String replayableReplay1 = "replayString1";
291                String replayableReplay2 = "replayString2";
292                String replayableTarget1 = "replayTargetString1";
293                String replayableTarget2 = "replayTargetString2";
294                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
295                                replayableTarget1);
296                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
297                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
298                replaySequence.add(replayable1);
299                replaySequence.add(replayable2);
300                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
301                                type);
302                fixture.replayEvents = replaySequence;
303                fixture.replayValid = replayValid;
304               
305                String typeOther = "typeString";
306                boolean replayValidOther = true;
307                String replayableReplayOther1 = "replayString3";
308                String replayableReplayOther2 = "replayString2";
309                String replaybleTargetOther1 = "replayTargetString1";
310                String replaybleTargetOther2 = "replayTargetString2";
311                MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
312                                replaybleTargetOther1);
313                MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
314                List<MockReplayable> replaySequenceOther = new LinkedList<MockReplayable>();
315                replaySequenceOther.add(replayableOther1);
316                replaySequenceOther.add(replayableOther2);
317                ReplayableEvent<MockReplayable> other = new ReplayableEvent<MockReplayable>(
318                                typeOther);
319                other.replayEvents = replaySequenceOther;
320                other.replayValid = replayValidOther;
321
322                boolean result = fixture.equals(other);
323
324                assertEquals(false, result);
325        }
326       
327        @Test
328        public void testEquals_4() throws Exception {
329                String type = "typeString";
330                boolean replayValid = true;
331                String replayableReplay1 = "replayString1";
332                String replayableReplay2 = "replayString2";
333                String replayableTarget1 = "replayTargetString1";
334                String replayableTarget2 = "replayTargetString2";
335                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
336                                replayableTarget1);
337                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
338                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
339                replaySequence.add(replayable1);
340                replaySequence.add(replayable2);
341                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
342                                type);
343                fixture.replayEvents = replaySequence;
344                fixture.replayValid = replayValid;
345               
346                String typeOther = "typeString";
347                boolean replayValidOther = true;
348                String replayableReplayOther1 = "replayString1";
349                String replayableReplayOther2 = "replayString3";
350                String replaybleTargetOther1 = "replayTargetString1";
351                String replaybleTargetOther2 = "replayTargetString2";
352                MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
353                                replaybleTargetOther1);
354                MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
355                List<MockReplayable> replaySequenceOther = new LinkedList<MockReplayable>();
356                replaySequenceOther.add(replayableOther1);
357                replaySequenceOther.add(replayableOther2);
358                ReplayableEvent<MockReplayable> other = new ReplayableEvent<MockReplayable>(
359                                typeOther);
360                other.replayEvents = replaySequenceOther;
361                other.replayValid = replayValidOther;
362
363                boolean result = fixture.equals(other);
364
365                assertEquals(false, result);
366        }
367       
368        @Test
369        public void testEquals_5() throws Exception {
370                String type = "typeString";
371                boolean replayValid = true;
372                String replayableReplay1 = "replayString1";
373                String replayableReplay2 = "replayString2";
374                String replayableTarget1 = "replayTargetString1";
375                String replayableTarget2 = "replayTargetString2";
376                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
377                                replayableTarget1);
378                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
379                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
380                replaySequence.add(replayable1);
381                replaySequence.add(replayable2);
382                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
383                                type);
384                fixture.replayEvents = replaySequence;
385                fixture.replayValid = replayValid;
386               
387                String typeOther = "typeString";
388                boolean replayValidOther = false;
389                String replayableReplayOther1 = "replayString1";
390                String replayableReplayOther2 = "replayString2";
391                String replaybleTargetOther1 = "replayTargetString1";
392                String replaybleTargetOther2 = "replayTargetString2";
393                MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
394                                replaybleTargetOther1);
395                MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
396                List<MockReplayable> replaySequenceOther = new LinkedList<MockReplayable>();
397                replaySequenceOther.add(replayableOther1);
398                replaySequenceOther.add(replayableOther2);
399                ReplayableEvent<MockReplayable> other = new ReplayableEvent<MockReplayable>(
400                                typeOther);
401                other.replayEvents = replaySequenceOther;
402                other.replayValid = replayValidOther;
403
404                boolean result = fixture.equals(other);
405
406                assertEquals(false, result);
407        }
408       
409        @Test
410        public void testEquals_6() throws Exception {
411                String type = "typeString";
412                boolean replayValid = true;
413                String replayableReplay1 = "replayString1";
414                String replayableReplay2 = "replayString2";
415                String replayableTarget1 = "replayTargetString1";
416                String replayableTarget2 = "replayTargetString2";
417                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
418                                replayableTarget1);
419                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
420                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
421                replaySequence.add(replayable1);
422                replaySequence.add(replayable2);
423                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
424                                type);
425                fixture.replayEvents = replaySequence;
426                fixture.replayValid = replayValid;
427
428                boolean result = fixture.equals(fixture);
429
430                assertEquals(true, result);
431        }
432       
433        @Test
434        public void testEqualsContract() throws Exception {
435                EqualsVerifier.forClass(ReplayableEvent.class)
436                .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).withRedefinedSuperclass()
437                .verify();
438        }
439
440        @Test
441        public void testGetReplayDecorator_1() throws Exception {
442                String type = "typeString";
443                StubReplayDecorator decorator = new StubReplayDecorator();
444                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
445                                type);
446                fixture.decorator = decorator;
447
448                IReplayDecorator result = fixture.getReplayDecorator();
449
450                assertEquals(decorator, result);
451        }
452
453        @Test
454        public void testGetReplayMessages_1() throws Exception {
455                String type = "typeString";
456                String replayableReplay1 = "replayString1";
457                String replayableReplay2 = "replayString2";
458                String replayableTarget1 = "replayTargetString1";
459                String replayableTarget2 = "replayTargetString2";
460                MockReplayable replayable1 = new MockReplayable(replayableReplay1,
461                                replayableTarget1);
462                MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
463                List<MockReplayable> replaySequence = new LinkedList<MockReplayable>();
464                replaySequence.add(replayable1);
465                replaySequence.add(replayable2);
466                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
467                                type);
468                fixture.replayEvents = replaySequence;
469
470                List<MockReplayable> result = fixture.getReplayMessages();
471
472                ListAssert.assertEquals(replaySequence, result);
473        }
474
475        @Test
476        public void testHasValidReplay_1() throws Exception {
477                String type = "typeString";
478                boolean replayValid = true;
479                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
480                                type);
481                fixture.replayValid = replayValid;
482
483                boolean result = fixture.hasValidReplay();
484
485                assertEquals(replayValid, result);
486        }
487       
488        @Test
489        public void testHasValidReplay_2() throws Exception {
490                String type = "typeString";
491                boolean replayValid = false;
492                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
493                                type);
494                fixture.replayValid = replayValid;
495
496                boolean result = fixture.hasValidReplay();
497
498                assertEquals(replayValid, result);
499        }
500
501        @Test
502        public void testInvalidateReplay_1() throws Exception {
503                String type = "typeString";
504                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
505                                type);
506               
507                fixture.invalidateReplay();
508
509                assertFalse(fixture.replayValid);
510        }
511       
512        @Test
513        public void testInvalidateReplay_2() throws Exception {
514                String type = "typeString";
515                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
516                                type);
517               
518                fixture.invalidateReplay();
519                fixture.invalidateReplay();
520
521                assertFalse(fixture.replayValid);
522        }
523
524        @Test
525        public void testSetDecorator_fixture_1() throws Exception {
526                String type = "typeString";
527                StubReplayDecorator decorator = new StubReplayDecorator();
528                ReplayableEvent<MockReplayable> fixture = new ReplayableEvent<MockReplayable>(
529                                type);
530
531                fixture.setDecorator(decorator);
532
533                assertEquals(decorator, fixture.decorator);
534        }
535
536        public static void main(String[] args) {
537                new org.junit.runner.JUnitCore().run(ReplayableEventTest.class);
538        }
539}
Note: See TracBrowser for help on using the repository browser.