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

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 9.5 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.eventcore;
16
17
18import java.util.LinkedList;
19import java.util.List;
20
21import org.junit.*;
22
23import de.ugoe.cs.autoquest.eventcore.Event;
24import de.ugoe.cs.autoquest.eventcore.IEventTarget;
25import de.ugoe.cs.autoquest.eventcore.IEventType;
26import de.ugoe.cs.autoquest.eventcore.IReplayable;
27
28import static org.junit.Assert.*;
29import static org.mockito.Mockito.*;
30
31/**
32 * The class <code>EventTest</code> contains tests for the class <code>{@link Event}</code>.
33 *
34 * @author Steffen Herbold
35 * @version 1.0
36 */
37public class EventTest {
38
39    @Test
40    public void testEvent_1() throws Exception {
41        Event result = new Event(mock(IEventType.class));
42
43        assertNotNull(result);
44    }
45
46    @Test(expected = java.lang.IllegalArgumentException.class)
47    public void testEvent_2() throws Exception {
48        new Event(null);
49    }
50
51    /*
52    @Test
53    public void testEquals_1() throws Exception {
54        IEventType type1 = mock(IEventType.class);
55        IEventType type2 = mock(IEventType.class);
56        // when(type1.equals(type2)).thenReturn(true);
57        Event fixture = new Event(type1);
58        Event other = new Event(type2);
59
60        boolean result = fixture.equals(other);
61
62        assertTrue(result);
63    }
64
65    @Test
66    public void testEquals_2() throws Exception {
67        String type1 = "typeString1";
68        String type2 = "typeString2";
69        Event fixture = new Event(type1);
70        Event other = new Event(type2);
71
72        boolean result = fixture.equals(other);
73
74        assertFalse(result);
75    }
76
77    @Test
78    public void testEquals_3() throws Exception {
79        String type1 = "typeString";
80        String type2 = "typeString";
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        assertTrue(result);
91    }
92
93    @Test
94    public void testEquals_4() throws Exception {
95        String type1 = "typeString1";
96        String type2 = "typeString2";
97        String target1 = "target";
98        String target2 = "target";
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_5() throws Exception {
111        String type1 = "typeString";
112        String type2 = "typeString";
113        String target1 = "target1";
114        String target2 = "target2";
115        Event fixture = new Event(type1);
116        fixture.target = target1;
117        Event other = new Event(type2);
118        other.target = target2;
119
120        boolean result = fixture.equals(other);
121
122        assertFalse(result);
123    }
124
125    @Test
126    public void testEquals_6() throws Exception {
127        String type = "typeString";
128        Event fixture = new Event(type);
129
130        boolean result = fixture.equals(fixture);
131
132        assertTrue(result);
133    }
134
135    @Test
136    public void testEqualsContract() throws Exception {
137        EqualsVerifier.forClass(Event.class).suppress(Warning.NONFINAL_FIELDS)
138            .withRedefinedSubclass(ReplayableEvent.class).verify();
139    }
140    */
141
142    @Test
143    public void testGetTarget_1() throws Exception {
144        IEventType type = mock(IEventType.class);
145        IEventTarget target = mock(IEventTarget.class);
146       
147        Event fixture = new Event(type);
148        fixture.setTarget(target);
149
150        IEventTarget result = fixture.getTarget();
151
152        assertSame(target, result);
153    }
154   
155   
156
157    @Test
158    public void testGetTarget_2() throws Exception {
159        IEventType type = mock(IEventType.class);
160        IEventTarget target = mock(IEventTarget.class);
161       
162        Event fixture = new Event(type, target);
163
164        IEventTarget result = fixture.getTarget();
165
166        assertSame(target, result);
167    }
168   
169    @Test
170    public void testGetTarget_3() throws Exception {
171        IEventType type = mock(IEventType.class);
172       
173        Event fixture = new Event(type);
174
175        IEventTarget result = fixture.getTarget();
176
177        assertNull(result);
178    }
179
180    @Test
181    public void testGetType_1() throws Exception {
182        IEventType type = mock(IEventType.class);
183       
184        Event fixture = new Event(type);
185
186        IEventType result = fixture.getType();
187
188        assertEquals(type, result);
189    }
190
191    @Test
192    public void testSetTarget_1() throws Exception {
193        IEventType type = mock(IEventType.class);
194        IEventTarget target = mock(IEventTarget.class);
195       
196        Event fixture = new Event(type);
197
198        boolean result = fixture.setTarget(target);
199
200        assertTrue(result);
201        assertEquals(target, fixture.getTarget());
202    }
203
204    @Test
205    public void testSetTarget_2() throws Exception {
206        IEventType type = mock(IEventType.class);
207        IEventTarget target1 = mock(IEventTarget.class);
208        IEventTarget target2 = mock(IEventTarget.class);
209       
210        Event fixture = new Event(type);
211
212        fixture.setTarget(target1);
213        boolean result = fixture.setTarget(target2);
214       
215        assertFalse(result);
216        assertEquals(target1, fixture.target);
217    }
218   
219    @Test
220    public void testSetTarget_3() throws Exception {
221        IEventType type = mock(IEventType.class);
222        IEventTarget target1 = mock(IEventTarget.class);
223        IEventTarget target2 = mock(IEventTarget.class);
224       
225        Event fixture = new Event(type, target1);
226
227        boolean result = fixture.setTarget(target2);
228       
229        assertFalse(result);
230        assertEquals(target1, fixture.target);
231    }
232
233    @Test
234    public void testGetId_1() throws Exception {
235        IEventType type = mock(IEventType.class);
236        when(type.toString()).thenReturn("typeString");
237        IEventTarget target = mock(IEventTarget.class);
238        when(target.getStringIdentifier()).thenReturn("targetString");
239       
240        Event fixture = new Event(type, target);
241
242        String result = fixture.toString();
243
244        assertEquals("typeString.targetString", result);
245    }
246   
247    @Test
248    public void testGetId_2() throws Exception {
249        IEventType type = mock(IEventType.class);
250        when(type.toString()).thenReturn("typeString");
251       
252        Event fixture = new Event(type);
253       
254        String result = fixture.toString();
255       
256        assertEquals("typeString", result);
257    }
258   
259    @Test
260    public void testAddReplayable_1() throws Exception {
261        IReplayable replayable = mock(IReplayable.class);
262
263        Event fixture = new Event(mock(IEventType.class));
264        fixture.addReplayable(replayable);
265
266        assertEquals(1, fixture.getReplayables().size());
267        assertEquals(replayable, fixture.getReplayables().get(0));
268    }
269
270    @Test
271    public void testAddReplayEvent_2() throws Exception {
272        IReplayable replayable1 = mock(IReplayable.class);
273        IReplayable replayable2 = mock(IReplayable.class);
274
275        Event fixture = new Event(mock(IEventType.class));
276        fixture.addReplayable(replayable1);
277        fixture.addReplayable(replayable2);
278
279        assertEquals(2, fixture.getReplayables().size());
280        assertEquals(replayable1, fixture.getReplayables().get(0));
281        assertEquals(replayable2, fixture.getReplayables().get(1));
282    }
283
284    @Test(expected = java.lang.IllegalArgumentException.class)
285    public void testAddReplayEvent_fixture_3() throws Exception {
286        Event fixture = new Event(mock(IEventType.class));
287        fixture.addReplayable(null);
288    }
289
290    @Test
291    public void testAddReplaySequence_1() throws Exception {
292        IReplayable replayable1 = mock(IReplayable.class);
293        IReplayable replayable2 = mock(IReplayable.class);
294
295        List<IReplayable> replayableSequences = new LinkedList<IReplayable>();
296        replayableSequences.add(replayable1);
297        replayableSequences.add(replayable2);
298
299        Event fixture = new Event(mock(IEventType.class));
300
301        fixture.addReplayableSequence(replayableSequences);
302
303        assertEquals(2, fixture.getReplayables().size());
304        assertEquals(replayable1, fixture.getReplayables().get(0));
305        assertEquals(replayable2, fixture.getReplayables().get(1));
306    }
307
308    @Test(expected = java.lang.IllegalArgumentException.class)
309    public void testAddReplaySequence_2() throws Exception {
310        Event fixture = new Event(mock(IEventType.class));
311
312        fixture.addReplayableSequence(null);
313    }
314
315    public static void main(String[] args) {
316        new org.junit.runner.JUnitCore().run(EventTest.class);
317    }
318}
Note: See TracBrowser for help on using the repository browser.