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

Last change on this file since 766 was 766, checked in by sherbold, 12 years ago
  • Property svn:mime-type set to text/plain
File size: 8.7 KB
Line 
1package de.ugoe.cs.quest.eventcore;
2
3
4import java.util.LinkedList;
5import java.util.List;
6
7import org.junit.*;
8
9import de.ugoe.cs.quest.eventcore.Event;
10
11import static org.junit.Assert.*;
12import static org.mockito.Mockito.*;
13
14/**
15 * The class <code>EventTest</code> contains tests for the class <code>{@link Event}</code>.
16 *
17 * @author Steffen Herbold
18 * @version 1.0
19 */
20public class EventTest {
21
22    @Test
23    public void testEvent_1() throws Exception {
24        Event result = new Event(mock(IEventType.class));
25
26        assertNotNull(result);
27    }
28
29    @Test(expected = java.lang.IllegalArgumentException.class)
30    public void testEvent_2() throws Exception {
31        new Event(null);
32    }
33
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);
42
43        boolean result = fixture.equals(other);
44
45        assertTrue(result);
46    }
47
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);
54
55        boolean result = fixture.equals(other);
56
57        assertFalse(result);
58    }
59
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;
70
71        boolean result = fixture.equals(other);
72
73        assertTrue(result);
74    }
75
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;
86
87        boolean result = fixture.equals(other);
88
89        assertFalse(result);
90    }
91
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;
102
103        boolean result = fixture.equals(other);
104
105        assertFalse(result);
106    }
107
108    @Test
109    public void testEquals_6() throws Exception {
110        String type = "typeString";
111        Event fixture = new Event(type);
112
113        boolean result = fixture.equals(fixture);
114
115        assertTrue(result);
116    }
117
118    @Test
119    public void testEqualsContract() throws Exception {
120        EqualsVerifier.forClass(Event.class).suppress(Warning.NONFINAL_FIELDS)
121            .withRedefinedSubclass(ReplayableEvent.class).verify();
122    }
123    */
124
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);
132
133        IEventTarget result = fixture.getTarget();
134
135        assertSame(target, result);
136    }
137   
138   
139
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);
146
147        IEventTarget result = fixture.getTarget();
148
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);
157
158        IEventTarget result = fixture.getTarget();
159
160        assertNull(result);
161    }
162
163    @Test
164    public void testGetType_1() throws Exception {
165        IEventType type = mock(IEventType.class);
166       
167        Event fixture = new Event(type);
168
169        IEventType result = fixture.getType();
170
171        assertEquals(type, result);
172    }
173
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);
180
181        boolean result = fixture.setTarget(target);
182
183        assertTrue(result);
184        assertEquals(target, fixture.getTarget());
185    }
186
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);
194
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);
209
210        boolean result = fixture.setTarget(target2);
211       
212        assertFalse(result);
213        assertEquals(target1, fixture.target);
214    }
215
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);
224
225        String result = fixture.toString();
226
227        assertEquals("typeString.targetString", result);
228    }
229   
230    @Test
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
243    public void testAddReplayable_1() throws Exception {
244        IReplayable replayable = mock(IReplayable.class);
245
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.lang.IllegalArgumentException.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.lang.IllegalArgumentException.class)
292    public void testAddReplaySequence_2() throws Exception {
293        Event fixture = new Event(mock(IEventType.class));
294
295        fixture.addReplayableSequence(null);
296    }
297
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.