Announcement Announcement Module
No announcement yet.
Testing Message Not Sent Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Testing Message Not Sent

    Hi Spring Team,

    I need to write a test to verify that a message has not been sent to a channel. I have written as shown below:

        public void onMessageShouldNotBeSent() {
            //onMessage can send or not depending on the message it receives
            Message<?> msg = myChannel.receive(500);
    It seems a little counter-intuitive to do it this way. What if a message was sent, but doesn't arrive until X seconds pass?
    Last edited by Gary Russell; Jul 11th, 2013, 10:59 AM.

  • #2
    Not sure what you mean; if it was sent to that channel it must be received.

    But this test won't work if the message is sent 500ms later.


    • #3
      That's my problem. Let's say I set the timeout to 5000ms. This adds 5 seconds to my test suite which slows things down, but it provides a larger time frame in which to receive a message.

      UPDATE: I got around this problem by using Mockito.verify to ensure that a mock instance of the channel in question did not have its "send" method invoked.


      • #4
        Now I see what you are saying.

        Yes, this is harder to verify than a positive test, especially in a multi-threaded environment; however, in this case, since (presumably) the send would have happened on the test runner's thread (that called onMessage()), you could simply have used myChannel.receive(0).