[547] | 1 |
|
---|
[433] | 2 | package de.ugoe.cs.quest.eventcore;
|
---|
[338] | 3 |
|
---|
| 4 |
|
---|
| 5 | import org.junit.*;
|
---|
| 6 |
|
---|
[433] | 7 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
[432] | 8 |
|
---|
[338] | 9 | import static org.junit.Assert.*;
|
---|
[547] | 10 | import static org.mockito.Mockito.*;
|
---|
[338] | 11 |
|
---|
| 12 | /**
|
---|
[547] | 13 | * The class <code>EventTest</code> contains tests for the class <code>{@link Event}</code>.
|
---|
[338] | 14 | *
|
---|
| 15 | * @author Steffen Herbold
|
---|
| 16 | * @version 1.0
|
---|
| 17 | */
|
---|
| 18 | public class EventTest {
|
---|
| 19 |
|
---|
[547] | 20 | @Test
|
---|
| 21 | public void testEvent_1() throws Exception {
|
---|
| 22 | Event result = new Event(mock(IEventType.class));
|
---|
[338] | 23 |
|
---|
[547] | 24 | assertNotNull(result);
|
---|
| 25 | }
|
---|
[338] | 26 |
|
---|
[547] | 27 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
| 28 | public void testEvent_2() throws Exception {
|
---|
| 29 | new Event(null);
|
---|
| 30 | }
|
---|
[338] | 31 |
|
---|
[547] | 32 | /*
|
---|
| 33 | @Test
|
---|
| 34 | public void testEquals_1() throws Exception {
|
---|
| 35 | IEventType type1 = mock(IEventType.class);
|
---|
| 36 | IEventType type2 = mock(IEventType.class);
|
---|
| 37 | // when(type1.equals(type2)).thenReturn(true);
|
---|
| 38 | Event fixture = new Event(type1);
|
---|
| 39 | Event other = new Event(type2);
|
---|
[338] | 40 |
|
---|
[547] | 41 | boolean result = fixture.equals(other);
|
---|
[338] | 42 |
|
---|
[547] | 43 | assertTrue(result);
|
---|
| 44 | }
|
---|
[338] | 45 |
|
---|
[547] | 46 | @Test
|
---|
| 47 | public void testEquals_2() throws Exception {
|
---|
| 48 | String type1 = "typeString1";
|
---|
| 49 | String type2 = "typeString2";
|
---|
| 50 | Event fixture = new Event(type1);
|
---|
| 51 | Event other = new Event(type2);
|
---|
[338] | 52 |
|
---|
[547] | 53 | boolean result = fixture.equals(other);
|
---|
[338] | 54 |
|
---|
[547] | 55 | assertFalse(result);
|
---|
| 56 | }
|
---|
[338] | 57 |
|
---|
[547] | 58 | @Test
|
---|
| 59 | public void testEquals_3() throws Exception {
|
---|
| 60 | String type1 = "typeString";
|
---|
| 61 | String type2 = "typeString";
|
---|
| 62 | String target1 = "target";
|
---|
| 63 | String target2 = "target";
|
---|
| 64 | Event fixture = new Event(type1);
|
---|
| 65 | fixture.target = target1;
|
---|
| 66 | Event other = new Event(type2);
|
---|
| 67 | other.target = target2;
|
---|
[338] | 68 |
|
---|
[547] | 69 | boolean result = fixture.equals(other);
|
---|
[338] | 70 |
|
---|
[547] | 71 | assertTrue(result);
|
---|
| 72 | }
|
---|
[338] | 73 |
|
---|
[547] | 74 | @Test
|
---|
| 75 | public void testEquals_4() throws Exception {
|
---|
| 76 | String type1 = "typeString1";
|
---|
| 77 | String type2 = "typeString2";
|
---|
| 78 | String target1 = "target";
|
---|
| 79 | String target2 = "target";
|
---|
| 80 | Event fixture = new Event(type1);
|
---|
| 81 | fixture.target = target1;
|
---|
| 82 | Event other = new Event(type2);
|
---|
| 83 | other.target = target2;
|
---|
[338] | 84 |
|
---|
[547] | 85 | boolean result = fixture.equals(other);
|
---|
[338] | 86 |
|
---|
[547] | 87 | assertFalse(result);
|
---|
| 88 | }
|
---|
[338] | 89 |
|
---|
[547] | 90 | @Test
|
---|
| 91 | public void testEquals_5() throws Exception {
|
---|
| 92 | String type1 = "typeString";
|
---|
| 93 | String type2 = "typeString";
|
---|
| 94 | String target1 = "target1";
|
---|
| 95 | String target2 = "target2";
|
---|
| 96 | Event fixture = new Event(type1);
|
---|
| 97 | fixture.target = target1;
|
---|
| 98 | Event other = new Event(type2);
|
---|
| 99 | other.target = target2;
|
---|
[338] | 100 |
|
---|
[547] | 101 | boolean result = fixture.equals(other);
|
---|
[338] | 102 |
|
---|
[547] | 103 | assertFalse(result);
|
---|
| 104 | }
|
---|
[338] | 105 |
|
---|
[547] | 106 | @Test
|
---|
| 107 | public void testEquals_6() throws Exception {
|
---|
| 108 | String type = "typeString";
|
---|
| 109 | Event fixture = new Event(type);
|
---|
[338] | 110 |
|
---|
[547] | 111 | boolean result = fixture.equals(fixture);
|
---|
[338] | 112 |
|
---|
[547] | 113 | assertTrue(result);
|
---|
| 114 | }
|
---|
[338] | 115 |
|
---|
[547] | 116 | @Test
|
---|
| 117 | public void testEqualsContract() throws Exception {
|
---|
| 118 | EqualsVerifier.forClass(Event.class).suppress(Warning.NONFINAL_FIELDS)
|
---|
| 119 | .withRedefinedSubclass(ReplayableEvent.class).verify();
|
---|
| 120 | }
|
---|
| 121 | */
|
---|
[338] | 122 |
|
---|
[547] | 123 | @Test
|
---|
| 124 | public void testGetTarget_1() throws Exception {
|
---|
| 125 | IEventType type = mock(IEventType.class);
|
---|
| 126 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 127 |
|
---|
| 128 | Event fixture = new Event(type);
|
---|
| 129 | fixture.setTarget(target);
|
---|
[338] | 130 |
|
---|
[547] | 131 | IEventTarget result = fixture.getTarget();
|
---|
[338] | 132 |
|
---|
[547] | 133 | assertSame(target, result);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
[338] | 137 |
|
---|
[547] | 138 | @Test
|
---|
| 139 | public void testGetTarget_2() throws Exception {
|
---|
| 140 | IEventType type = mock(IEventType.class);
|
---|
| 141 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 142 |
|
---|
| 143 | Event fixture = new Event(type, target);
|
---|
[338] | 144 |
|
---|
[547] | 145 | IEventTarget result = fixture.getTarget();
|
---|
[338] | 146 |
|
---|
[547] | 147 | assertSame(target, result);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | @Test
|
---|
| 151 | public void testGetTarget_3() throws Exception {
|
---|
| 152 | IEventType type = mock(IEventType.class);
|
---|
| 153 |
|
---|
| 154 | Event fixture = new Event(type);
|
---|
[338] | 155 |
|
---|
[547] | 156 | IEventTarget result = fixture.getTarget();
|
---|
[338] | 157 |
|
---|
[547] | 158 | assertNull(result);
|
---|
| 159 | }
|
---|
[338] | 160 |
|
---|
[547] | 161 | @Test
|
---|
| 162 | public void testGetType_1() throws Exception {
|
---|
| 163 | IEventType type = mock(IEventType.class);
|
---|
| 164 |
|
---|
| 165 | Event fixture = new Event(type);
|
---|
[338] | 166 |
|
---|
[547] | 167 | IEventType result = fixture.getType();
|
---|
[338] | 168 |
|
---|
[547] | 169 | assertEquals(type, result);
|
---|
| 170 | }
|
---|
[338] | 171 |
|
---|
[547] | 172 | @Test
|
---|
| 173 | public void testSetTarget_1() throws Exception {
|
---|
| 174 | IEventType type = mock(IEventType.class);
|
---|
| 175 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 176 |
|
---|
| 177 | Event fixture = new Event(type);
|
---|
[338] | 178 |
|
---|
[547] | 179 | boolean result = fixture.setTarget(target);
|
---|
[338] | 180 |
|
---|
[547] | 181 | assertTrue(result);
|
---|
| 182 | assertEquals(target, fixture.getTarget());
|
---|
| 183 | }
|
---|
[338] | 184 |
|
---|
[547] | 185 | @Test
|
---|
| 186 | public void testSetTarget_2() throws Exception {
|
---|
| 187 | IEventType type = mock(IEventType.class);
|
---|
| 188 | IEventTarget target1 = mock(IEventTarget.class);
|
---|
| 189 | IEventTarget target2 = mock(IEventTarget.class);
|
---|
| 190 |
|
---|
| 191 | Event fixture = new Event(type);
|
---|
[338] | 192 |
|
---|
[547] | 193 | fixture.setTarget(target1);
|
---|
| 194 | boolean result = fixture.setTarget(target2);
|
---|
| 195 |
|
---|
| 196 | assertFalse(result);
|
---|
| 197 | assertEquals(target1, fixture.target);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | @Test
|
---|
| 201 | public void testSetTarget_3() throws Exception {
|
---|
| 202 | IEventType type = mock(IEventType.class);
|
---|
| 203 | IEventTarget target1 = mock(IEventTarget.class);
|
---|
| 204 | IEventTarget target2 = mock(IEventTarget.class);
|
---|
| 205 |
|
---|
| 206 | Event fixture = new Event(type, target1);
|
---|
[338] | 207 |
|
---|
[547] | 208 | boolean result = fixture.setTarget(target2);
|
---|
| 209 |
|
---|
| 210 | assertFalse(result);
|
---|
| 211 | assertEquals(target1, fixture.target);
|
---|
| 212 | }
|
---|
[338] | 213 |
|
---|
[547] | 214 | @Test
|
---|
| 215 | public void testToString_1() throws Exception {
|
---|
| 216 | IEventType type = mock(IEventType.class);
|
---|
| 217 | when(type.toString()).thenReturn("typeString");
|
---|
| 218 | IEventTarget target = mock(IEventTarget.class);
|
---|
| 219 | when(target.toString()).thenReturn("targetString");
|
---|
| 220 |
|
---|
| 221 | Event fixture = new Event(type, target);
|
---|
[338] | 222 |
|
---|
[547] | 223 | String result = fixture.toString();
|
---|
[338] | 224 |
|
---|
[547] | 225 | assertEquals("(typeString;targetString)", result);
|
---|
| 226 | }
|
---|
[338] | 227 |
|
---|
[547] | 228 | public static void main(String[] args) {
|
---|
| 229 | new org.junit.runner.JUnitCore().run(EventTest.class);
|
---|
| 230 | }
|
---|
| 231 | }
|
---|