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

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