Pranav
Pranav

Reputation: 123

channel iterator partially covered [1 of 2 branches] kotlin

I have written a custom SQS consumer wherein :

However, when writing unit tests I am unable to achieve 100% test coverage kover or with sonar. The kover/sonar plugin complains about partially covered while loop [highlighted in yellow] and I cannot understand which scenario have I missed

Unit test cases:

  1. When Single message
  2. When no message
  3. When 10+ message
  4. when "no more" message after polling once
  5. When an error

Actual code :

enter image description here

I looked inside of itr.hasnext() method and there are several branches but unable to understand why code coverage is considering internal methods of the library for code coverage ?

Thanks in advance

Upvotes: 0

Views: 321

Answers (1)

Pranav
Pranav

Reputation: 123

Found the issue:

Basically, the hasNext() method from AbstractChannel class never returned false.

enter image description here

So, mocked the channel, wrote a custom iterator and made hasNext() return false

val mockChannel: Channel<Message> = mock()
whenever(mockChannel.iterator()).thenReturn(Itr())

enter image description here

And it worked like a charm

enter image description here

Upvotes: 0

Related Questions