-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit tests in event bridge module (#28)
- Loading branch information
1 parent
dc78bc6
commit 8d63c28
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
event-bridge/src/main/java/com/amplitude/eventbridge/EventBridgeContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
event-bridge/src/test/kotlin/com/amplitude/eventbridge/EventBridgeContainerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.amplitude.eventbridge | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class EventBridgeContainerTest { | ||
|
||
@Test | ||
fun `test getInstance return same instance for certain name`() { | ||
val eventBridge1 = EventBridgeContainer.getInstance("testInstance") | ||
val eventBridge2 = EventBridgeContainer.getInstance("testInstance") | ||
Assertions.assertEquals(eventBridge1, eventBridge2) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
event-bridge/src/test/kotlin/com/amplitude/eventbridge/EventBridgeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.amplitude.eventbridge | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class EventBridgeTest { | ||
|
||
@Test | ||
fun `test addEventListener, sendEvent, listener called`() { | ||
val testEvent = Event("test") | ||
val identifyEvent = Event("identify") | ||
val eventBridge = EventBridgeImpl() | ||
var wasEventReceiverCalled = false | ||
eventBridge.setEventReceiver( | ||
EventChannel.EVENT, | ||
object : EventReceiver { | ||
override fun receive(channel: EventChannel, event: Event) { | ||
assertEquals(event, testEvent) | ||
wasEventReceiverCalled = true | ||
} | ||
} | ||
) | ||
eventBridge.setEventReceiver( | ||
EventChannel.IDENTIFY, | ||
object : EventReceiver { | ||
override fun receive(channel: EventChannel, event: Event) { | ||
assertEquals(event, identifyEvent) | ||
wasEventReceiverCalled = true | ||
} | ||
} | ||
) | ||
eventBridge.sendEvent(EventChannel.EVENT, testEvent) | ||
eventBridge.sendEvent(EventChannel.IDENTIFY, identifyEvent) | ||
assertTrue(wasEventReceiverCalled) | ||
} | ||
|
||
@Test | ||
fun `test sendEvent first, add listener later and listener receive event`() { | ||
val testEvent1 = Event("test1") | ||
val testEvent2 = Event("test2") | ||
val testEvent3 = Event("test3") | ||
val eventBridge = EventBridgeImpl() | ||
eventBridge.sendEvent(EventChannel.EVENT, testEvent1) | ||
eventBridge.sendEvent(EventChannel.EVENT, testEvent2) | ||
eventBridge.sendEvent(EventChannel.EVENT, testEvent3) | ||
var eventCount = 0 | ||
eventBridge.setEventReceiver( | ||
EventChannel.EVENT, | ||
object : EventReceiver { | ||
override fun receive(channel: EventChannel, event: Event) { | ||
eventCount++ | ||
} | ||
} | ||
) | ||
assertEquals(3, eventCount) | ||
} | ||
} |