[547] | 1 |
|
---|
[433] | 2 | package de.ugoe.cs.quest.eventcore;
|
---|
[338] | 3 |
|
---|
| 4 |
|
---|
[548] | 5 | import java.util.LinkedList;
|
---|
| 6 | import java.util.List;
|
---|
| 7 |
|
---|
[338] | 8 | import org.junit.*;
|
---|
| 9 |
|
---|
[433] | 10 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
[432] | 11 |
|
---|
[338] | 12 | import static org.junit.Assert.*;
|
---|
[547] | 13 | import 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 | */
|
---|
| 21 | public 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 |
|
---|
[547] | 228 | assertEquals("(typeString;targetString)", result);
|
---|
| 229 | }
|
---|
[548] | 230 |
|
---|
| 231 | @Test
|
---|
| 232 | public void testAddReplayable_1() throws Exception {
|
---|
| 233 | IReplayable replayable = mock(IReplayable.class);
|
---|
[338] | 234 |
|
---|
[548] | 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 |
|
---|
[547] | 287 | public static void main(String[] args) {
|
---|
| 288 | new org.junit.runner.JUnitCore().run(EventTest.class);
|
---|
| 289 | }
|
---|
| 290 | }
|
---|