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

Last change on this file since 548 was 548, checked in by sherbold, 12 years ago
  • countless adaptations throughout nearly all components to remove errors introduced due to the refactoring of the event core
  • Property svn:mime-type set to text/plain
File size: 8.3 KB
Line 
1
2package de.ugoe.cs.quest.eventcore;
3
4
5import java.util.LinkedList;
6import java.util.List;
7
8import org.junit.*;
9
10import de.ugoe.cs.quest.eventcore.Event;
11
12import static org.junit.Assert.*;
13import static org.mockito.Mockito.*;
14
15/**
16 * The class <code>EventTest</code> contains tests for the class <code>{@link Event}</code>.
17 *
18 * @author Steffen Herbold
19 * @version 1.0
20 */
21public class EventTest {
22
23    @Test
24    public void testEvent_1() throws Exception {
25        Event result = new Event(mock(IEventType.class));
26
27        assertNotNull(result);
28    }
29
30    @Test(expected = java.security.InvalidParameterException.class)
31    public void testEvent_2() throws Exception {
32        new Event(null);
33    }
34
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);
43
44        boolean result = fixture.equals(other);
45
46        assertTrue(result);
47    }
48
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);
55
56        boolean result = fixture.equals(other);
57
58        assertFalse(result);
59    }
60
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;
71
72        boolean result = fixture.equals(other);
73
74        assertTrue(result);
75    }
76
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;
87
88        boolean result = fixture.equals(other);
89
90        assertFalse(result);
91    }
92
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;
103
104        boolean result = fixture.equals(other);
105
106        assertFalse(result);
107    }
108
109    @Test
110    public void testEquals_6() throws Exception {
111        String type = "typeString";
112        Event fixture = new Event(type);
113
114        boolean result = fixture.equals(fixture);
115
116        assertTrue(result);
117    }
118
119    @Test
120    public void testEqualsContract() throws Exception {
121        EqualsVerifier.forClass(Event.class).suppress(Warning.NONFINAL_FIELDS)
122            .withRedefinedSubclass(ReplayableEvent.class).verify();
123    }
124    */
125
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);
133
134        IEventTarget result = fixture.getTarget();
135
136        assertSame(target, result);
137    }
138   
139   
140
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);
147
148        IEventTarget result = fixture.getTarget();
149
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);
158
159        IEventTarget result = fixture.getTarget();
160
161        assertNull(result);
162    }
163
164    @Test
165    public void testGetType_1() throws Exception {
166        IEventType type = mock(IEventType.class);
167       
168        Event fixture = new Event(type);
169
170        IEventType result = fixture.getType();
171
172        assertEquals(type, result);
173    }
174
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);
181
182        boolean result = fixture.setTarget(target);
183
184        assertTrue(result);
185        assertEquals(target, fixture.getTarget());
186    }
187
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);
195
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);
210
211        boolean result = fixture.setTarget(target2);
212       
213        assertFalse(result);
214        assertEquals(target1, fixture.target);
215    }
216
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);
225
226        String result = fixture.toString();
227
228        assertEquals("(typeString;targetString)", result);
229    }
230   
231    @Test
232    public void testAddReplayable_1() throws Exception {
233        IReplayable replayable = mock(IReplayable.class);
234
235        Event fixture = new Event(mock(IEventType.class));
236        fixture.addReplayable(replayable);
237
238        assertEquals(1, fixture.getReplayables().size());
239        assertEquals(replayable, fixture.getReplayables().get(0));
240    }
241
242    @Test
243    public void testAddReplayEvent_2() throws Exception {
244        IReplayable replayable1 = mock(IReplayable.class);
245        IReplayable replayable2 = mock(IReplayable.class);
246
247        Event fixture = new Event(mock(IEventType.class));
248        fixture.addReplayable(replayable1);
249        fixture.addReplayable(replayable2);
250
251        assertEquals(2, fixture.getReplayables().size());
252        assertEquals(replayable1, fixture.getReplayables().get(0));
253        assertEquals(replayable2, fixture.getReplayables().get(1));
254    }
255
256    @Test(expected = java.security.InvalidParameterException.class)
257    public void testAddReplayEvent_fixture_3() throws Exception {
258        Event fixture = new Event(mock(IEventType.class));
259        fixture.addReplayable(null);
260    }
261
262    @Test
263    public void testAddReplaySequence_1() throws Exception {
264        IReplayable replayable1 = mock(IReplayable.class);
265        IReplayable replayable2 = mock(IReplayable.class);
266
267        List<IReplayable> replayableSequences = new LinkedList<IReplayable>();
268        replayableSequences.add(replayable1);
269        replayableSequences.add(replayable2);
270
271        Event fixture = new Event(mock(IEventType.class));
272
273        fixture.addReplayableSequence(replayableSequences);
274
275        assertEquals(2, fixture.getReplayables().size());
276        assertEquals(replayable1, fixture.getReplayables().get(0));
277        assertEquals(replayable2, fixture.getReplayables().get(1));
278    }
279
280    @Test(expected = java.security.InvalidParameterException.class)
281    public void testAddReplaySequence_2() throws Exception {
282        Event fixture = new Event(mock(IEventType.class));
283
284        fixture.addReplayableSequence(null);
285    }
286
287    public static void main(String[] args) {
288        new org.junit.runner.JUnitCore().run(EventTest.class);
289    }
290}
Note: See TracBrowser for help on using the repository browser.