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

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