Reputation: 123
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:
Actual code :
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
Reputation: 123
Found the issue:
Basically, the hasNext() method from AbstractChannel
class never returned false.
So, mocked the channel, wrote a custom iterator and made hasNext()
return false
val mockChannel: Channel<Message> = mock()
whenever(mockChannel.iterator()).thenReturn(Itr())
And it worked like a charm
Upvotes: 0