'Redisson Pub/Sub unit test, fail in higher order function but unit test still pass

I have a Publish Module and Subscribe Module

I am writing a Unit Test to test if I get the correct object from subscribe when publish something

My Unit Test: Add Listner to a Topic, publish a message --> Assert that msg from listener

I get on console an Assert Error but the test case still pass. (I assert in pass-in higher-order function)

This is my Test case

 @Test
  fun testRedisPubSubSuccess() {
    testComponent = DaggerMoMoListenerTest_MainComponent.builder().addExecutor(executor).build()
    val testTopic = "UnitTest Topic"
    val testObject = PersonTestingObject("Adam", 1, "[email protected]")
    val sub = testComponent.getSub()
    sub.subscribe(testTopic, PersonTestingObject::class.java) { msg ->
      // This should fail
      Assert.assertNull(msg)
    }
    testComponent.getPub().publish(testObject, testTopic, "unused")
    Thread.sleep(5000)
  }
}

This is my publish function

  override fun publish(item: T, topicName: String, actionType: String) {
    val redisInstance = redisClient.getInstance("test")
    val topic: RTopic = redisInstance.getTopic(topicName)
    topic.publish(item)
  }

this is my subscribe function

  override fun subscribe(
    topicName: String,
    packageType: Class<out T>,
    onTrigger: (T) -> Unit
  ) { // ::class.jav
    val redisInstance = redisClient.getInstance("test")
    val topic: RTopic = redisInstance.getTopic(topicName)
    topic.addListener(packageType) { channel, msg ->
      onTrigger(msg)
    }
  }

On Debug console I got Assert error but test case still pass

Exception in thread "redisson-3-2" java.lang.AssertionError: expected null, but was:<test.PersonTestingObject@6f087163>

How can I make this Assert error effect to the test case?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source