Skip to content

Commit

Permalink
[test] Fixed TestGameEvent Constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
yymin1022 committed Nov 30, 2024
1 parent a0d014c commit 4560a95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public void setUp() {
public void addEventListener_shouldAddListener() {
// Act
manager.addEventListener(EventType.RABBIT_MOVED, listener);
manager.fireEvent(new TestGameEvent(EventType.RABBIT_MOVED, "test"));
TestGameEvent event = new TestGameEvent();
event.setTestData("test");
manager.fireEvent(event);

// Assert
assertEquals(1, listener.getReceivedEvents().size());
GameEvent event = listener.getReceivedEvents().get(0);
assertEquals(EventType.RABBIT_MOVED, event.getType());
assertTrue(event.getEventData().containsKey("testData"));
assertEquals("test", event.getEventData().get("testData"));
GameEvent receivedEvent = listener.getReceivedEvents().get(0);
assertEquals(EventType.RABBIT_MOVED, receivedEvent.getType());
assertEquals("test", receivedEvent.getEventData().get("testData"));
}

@Test
Expand All @@ -55,7 +56,9 @@ public void removeEventListener_shouldRemoveListener() {

// Act
manager.removeEventListener(EventType.RABBIT_MOVED, listener);
manager.fireEvent(new TestGameEvent(EventType.RABBIT_MOVED, "test"));
TestGameEvent event = new TestGameEvent();
event.setTestData("test");
manager.fireEvent(event);

// Assert
assertEquals(0, listener.getReceivedEvents().size());
Expand All @@ -69,7 +72,9 @@ public void fireEvent_shouldNotifyOnlyMatchingListeners() {
manager.addEventListener(EventType.LEVEL_WON, otherListener);

// Act
manager.fireEvent(new TestGameEvent(EventType.RABBIT_MOVED, "test"));
TestGameEvent event = new TestGameEvent();
event.setTestData("test");
manager.fireEvent(event);

// Assert
assertEquals(1, listener.getReceivedEvents().size());
Expand All @@ -84,7 +89,9 @@ public void multipleListeners_shouldAllReceiveEvents() {
manager.addEventListener(EventType.RABBIT_MOVED, listener2);

// Act
manager.fireEvent(new TestGameEvent(EventType.RABBIT_MOVED, "test"));
TestGameEvent event = new TestGameEvent();
event.setTestData("test");
manager.fireEvent(event);

// Assert
assertEquals(1, listener.getReceivedEvents().size());
Expand Down
8 changes: 2 additions & 6 deletions src/engine/test/rabbitescape/engine/events/TestGameEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ public class TestGameEvent implements GameEvent {
private String testData;

public TestGameEvent() {
this(EventType.RABBIT_MOVED, "default");
}

public TestGameEvent(EventType type, String testData) {
this.type = type;
this.testData = testData;
this.type = EventType.RABBIT_MOVED;
this.testData = "default";
}

@Override
Expand Down

0 comments on commit 4560a95

Please sign in to comment.