Writing a test case for the publish-subscribe model

Let's write test cases to check the publishMessage() and listenToMessage() functions. 

We can write a PublisherTest as follows:

class PublisherTest {    @Test    fun testPublishMessage() {        val seContainerInitializer = SeContainerInitializer.newInstance()        val seContainer = seContainerInitializer.initialize()        val publisherInstance = seContainer.select(Publisher::class.java)        val publisher = publisherInstance.get()        Assert.assertNotNull(publisher)        val message = "Test messgage for topic111"        publisher.publishMessage(message)    }}

We initialize the container to inject the dependencies. We get an instance of Publisher and invoke the publishMessage() function by passing the message. This message will be published ...

Get Kotlin for Enterprise Applications using Java EE now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.