source: trunk/quest-core-events-test/src/test/java/de/ugoe/cs/quest/eventcore/EventTest.java @ 681

Last change on this file since 681 was 655, checked in by pharms, 12 years ago
  • removed old copyright file header
  • Property svn:mime-type set to text/plain
File size: 8.7 KB
RevLine 
[433]1package de.ugoe.cs.quest.eventcore;
[338]2
3
[548]4import java.util.LinkedList;
5import java.util.List;
6
[338]7import org.junit.*;
8
[433]9import de.ugoe.cs.quest.eventcore.Event;
[432]10
[338]11import static org.junit.Assert.*;
[547]12import static org.mockito.Mockito.*;
[338]13
14/**
[547]15 * The class <code>EventTest</code> contains tests for the class <code>{@link Event}</code>.
[338]16 *
17 * @author Steffen Herbold
18 * @version 1.0
19 */
20public class EventTest {
21
[547]22    @Test
23    public void testEvent_1() throws Exception {
24        Event result = new Event(mock(IEventType.class));
[338]25
[547]26        assertNotNull(result);
27    }
[338]28
[547]29    @Test(expected = java.security.InvalidParameterException.class)
30    public void testEvent_2() throws Exception {
31        new Event(null);
32    }
[338]33
[547]34    /*
35    @Test
36    public void testEquals_1() throws Exception {
37        IEventType type1 = mock(IEventType.class);
38        IEventType type2 = mock(IEventType.class);
39        // when(type1.equals(type2)).thenReturn(true);
40        Event fixture = new Event(type1);
41        Event other = new Event(type2);
[338]42
[547]43        boolean result = fixture.equals(other);
[338]44
[547]45        assertTrue(result);
46    }
[338]47
[547]48    @Test
49    public void testEquals_2() throws Exception {
50        String type1 = "typeString1";
51        String type2 = "typeString2";
52        Event fixture = new Event(type1);
53        Event other = new Event(type2);
[338]54
[547]55        boolean result = fixture.equals(other);
[338]56
[547]57        assertFalse(result);
58    }
[338]59
[547]60    @Test
61    public void testEquals_3() throws Exception {
62        String type1 = "typeString";
63        String type2 = "typeString";
64        String target1 = "target";
65        String target2 = "target";
66        Event fixture = new Event(type1);
67        fixture.target = target1;
68        Event other = new Event(type2);
69        other.target = target2;
[338]70
[547]71        boolean result = fixture.equals(other);
[338]72
[547]73        assertTrue(result);
74    }
[338]75
[547]76    @Test
77    public void testEquals_4() throws Exception {
78        String type1 = "typeString1";
79        String type2 = "typeString2";
80        String target1 = "target";
81        String target2 = "target";
82        Event fixture = new Event(type1);
83        fixture.target = target1;
84        Event other = new Event(type2);
85        other.target = target2;
[338]86
[547]87        boolean result = fixture.equals(other);
[338]88
[547]89        assertFalse(result);
90    }
[338]91
[547]92    @Test
93    public void testEquals_5() throws Exception {
94        String type1 = "typeString";
95        String type2 = "typeString";
96        String target1 = "target1";
97        String target2 = "target2";
98        Event fixture = new Event(type1);
99        fixture.target = target1;
100        Event other = new Event(type2);
101        other.target = target2;
[338]102
[547]103        boolean result = fixture.equals(other);
[338]104
[547]105        assertFalse(result);
106    }
[338]107
[547]108    @Test
109    public void testEquals_6() throws Exception {
110        String type = "typeString";
111        Event fixture = new Event(type);
[338]112
[547]113        boolean result = fixture.equals(fixture);
[338]114
[547]115        assertTrue(result);
116    }
[338]117
[547]118    @Test
119    public void testEqualsContract() throws Exception {
120        EqualsVerifier.forClass(Event.class).suppress(Warning.NONFINAL_FIELDS)
121            .withRedefinedSubclass(ReplayableEvent.class).verify();
122    }
123    */
[338]124
[547]125    @Test
126    public void testGetTarget_1() throws Exception {
127        IEventType type = mock(IEventType.class);
128        IEventTarget target = mock(IEventTarget.class);
129       
130        Event fixture = new Event(type);
131        fixture.setTarget(target);
[338]132
[547]133        IEventTarget result = fixture.getTarget();
[338]134
[547]135        assertSame(target, result);
136    }
137   
138   
[338]139
[547]140    @Test
141    public void testGetTarget_2() throws Exception {
142        IEventType type = mock(IEventType.class);
143        IEventTarget target = mock(IEventTarget.class);
144       
145        Event fixture = new Event(type, target);
[338]146
[547]147        IEventTarget result = fixture.getTarget();
[338]148
[547]149        assertSame(target, result);
150    }
151   
152    @Test
153    public void testGetTarget_3() throws Exception {
154        IEventType type = mock(IEventType.class);
155       
156        Event fixture = new Event(type);
[338]157
[547]158        IEventTarget result = fixture.getTarget();
[338]159
[547]160        assertNull(result);
161    }
[338]162
[547]163    @Test
164    public void testGetType_1() throws Exception {
165        IEventType type = mock(IEventType.class);
166       
167        Event fixture = new Event(type);
[338]168
[547]169        IEventType result = fixture.getType();
[338]170
[547]171        assertEquals(type, result);
172    }
[338]173
[547]174    @Test
175    public void testSetTarget_1() throws Exception {
176        IEventType type = mock(IEventType.class);
177        IEventTarget target = mock(IEventTarget.class);
178       
179        Event fixture = new Event(type);
[338]180
[547]181        boolean result = fixture.setTarget(target);
[338]182
[547]183        assertTrue(result);
184        assertEquals(target, fixture.getTarget());
185    }
[338]186
[547]187    @Test
188    public void testSetTarget_2() throws Exception {
189        IEventType type = mock(IEventType.class);
190        IEventTarget target1 = mock(IEventTarget.class);
191        IEventTarget target2 = mock(IEventTarget.class);
192       
193        Event fixture = new Event(type);
[338]194
[547]195        fixture.setTarget(target1);
196        boolean result = fixture.setTarget(target2);
197       
198        assertFalse(result);
199        assertEquals(target1, fixture.target);
200    }
201   
202    @Test
203    public void testSetTarget_3() throws Exception {
204        IEventType type = mock(IEventType.class);
205        IEventTarget target1 = mock(IEventTarget.class);
206        IEventTarget target2 = mock(IEventTarget.class);
207       
208        Event fixture = new Event(type, target1);
[338]209
[547]210        boolean result = fixture.setTarget(target2);
211       
212        assertFalse(result);
213        assertEquals(target1, fixture.target);
214    }
[338]215
[547]216    @Test
217    public void testToString_1() throws Exception {
218        IEventType type = mock(IEventType.class);
219        when(type.toString()).thenReturn("typeString");
220        IEventTarget target = mock(IEventTarget.class);
221        when(target.toString()).thenReturn("targetString");
222       
223        Event fixture = new Event(type, target);
[338]224
[547]225        String result = fixture.toString();
[338]226
[568]227        assertEquals("typeString.targetString", result);
[547]228    }
[548]229   
230    @Test
[568]231    public void testToString_2() throws Exception {
232        IEventType type = mock(IEventType.class);
233        when(type.toString()).thenReturn("typeString");
234       
235        Event fixture = new Event(type);
236       
237        String result = fixture.toString();
238       
239        assertEquals("typeString", result);
240    }
241   
242    @Test
[548]243    public void testAddReplayable_1() throws Exception {
244        IReplayable replayable = mock(IReplayable.class);
[338]245
[548]246        Event fixture = new Event(mock(IEventType.class));
247        fixture.addReplayable(replayable);
248
249        assertEquals(1, fixture.getReplayables().size());
250        assertEquals(replayable, fixture.getReplayables().get(0));
251    }
252
253    @Test
254    public void testAddReplayEvent_2() throws Exception {
255        IReplayable replayable1 = mock(IReplayable.class);
256        IReplayable replayable2 = mock(IReplayable.class);
257
258        Event fixture = new Event(mock(IEventType.class));
259        fixture.addReplayable(replayable1);
260        fixture.addReplayable(replayable2);
261
262        assertEquals(2, fixture.getReplayables().size());
263        assertEquals(replayable1, fixture.getReplayables().get(0));
264        assertEquals(replayable2, fixture.getReplayables().get(1));
265    }
266
267    @Test(expected = java.security.InvalidParameterException.class)
268    public void testAddReplayEvent_fixture_3() throws Exception {
269        Event fixture = new Event(mock(IEventType.class));
270        fixture.addReplayable(null);
271    }
272
273    @Test
274    public void testAddReplaySequence_1() throws Exception {
275        IReplayable replayable1 = mock(IReplayable.class);
276        IReplayable replayable2 = mock(IReplayable.class);
277
278        List<IReplayable> replayableSequences = new LinkedList<IReplayable>();
279        replayableSequences.add(replayable1);
280        replayableSequences.add(replayable2);
281
282        Event fixture = new Event(mock(IEventType.class));
283
284        fixture.addReplayableSequence(replayableSequences);
285
286        assertEquals(2, fixture.getReplayables().size());
287        assertEquals(replayable1, fixture.getReplayables().get(0));
288        assertEquals(replayable2, fixture.getReplayables().get(1));
289    }
290
291    @Test(expected = java.security.InvalidParameterException.class)
292    public void testAddReplaySequence_2() throws Exception {
293        Event fixture = new Event(mock(IEventType.class));
294
295        fixture.addReplayableSequence(null);
296    }
297
[547]298    public static void main(String[] args) {
299        new org.junit.runner.JUnitCore().run(EventTest.class);
300    }
301}
Note: See TracBrowser for help on using the repository browser.