Test cases for TestDefaultDeviceCodeService#1368
Test cases for TestDefaultDeviceCodeService#1368Sangeeta19 wants to merge 9 commits intomitreid-connect:masterfrom
Conversation
TestDefaultDeviceCodeService.java uploaded
jricher
left a comment
There was a problem hiding this comment.
Looks good so far, looking to see the rest of the pieces filled out.
Codecov Report
@@ Coverage Diff @@
## master #1368 +/- ##
===========================================
+ Coverage 24.67% 25.37% +0.7%
- Complexity 888 914 +26
===========================================
Files 209 209
Lines 11673 11676 +3
Branches 2116 2116
===========================================
+ Hits 2880 2963 +83
+ Misses 8287 8199 -88
- Partials 506 514 +8
Continue to review full report at Codecov.
|
1) createNewDeviceCode() 2) approveDeviceCode()
Added unit tests to methods
unit test - public void clearExpiredDeviceCodes()
| expiredDeviceCodes1 = Sets.newHashSet(deviceCode1, deviceCode2); | ||
| expiredDeviceCodes2 = Sets.newHashSet(); | ||
|
|
||
| Mockito.when(repository.getExpiredCodes()).thenReturn(expiredDeviceCodes1, expiredDeviceCodes1,expiredDeviceCodes2); |
There was a problem hiding this comment.
You're getting the test to pass here through some side effects. If the underlying paging system were to change, it might suddenly fail because of these side effects.
There was a problem hiding this comment.
Justin,
Instead of invoking Mockito.veriyf() with hard code values like 2 and 4, invoking with size of set expiredDeviceCodes1 will solve the issue.
Is my understanding of the your comment is correct?
There was a problem hiding this comment.
will the below code snippet works in case if it is all about size:
Set expiredDeviceCodes1 = Sets.newHashSet(deviceCode1,deviceCode2);
Set expiredDeviceCodes2 = Sets.newHashSet();
Mockito.when(repository.getExpiredCodes())
.thenReturn(expiredDeviceCodes1,expiredDeviceCodes2);
service.clearExpiredDeviceCodes();
Mockito.verify(repository,times(expiredDeviceCodes1.size()))
.remove(Matchers.any(DeviceCode.class));
Mockito.verify(repository,times(expiredDeviceCodes1.size())).getExpiredCodes();
There was a problem hiding this comment.
It's not about size, it's about how you're making your repository respond. The size calls are an improvement, but that's not the main issue. You're having your mocked repository return a full list twice and an empty list regardless of whether or not the expirations have been performed on it in the mean time. In other words, it's passing because the service thinks it's doing the right thing but it would still pass if something else a little weird happened.
There was a problem hiding this comment.
By adding Sysout to method fetchPage() and doOperation(DeviceCode item) in implementation class, realized that for each call of fetchPage() : doOperation(DeviceCode item) calls are dependent on size of expiredCodesList, so all the items are removed.
Then after fetchPage() is called again , now empty set will be returned (from mocked repository) as it got emptied out in the last call.
This forced me to mock repository with list with elements for first call and zero elements in second call.
There was a problem hiding this comment.
But that's only true if things are emptied out as expected with each page.
jricher
left a comment
There was a problem hiding this comment.
build still failing and the side effect of the clear tests hasn't been fixed
|
Justin, I tried and I could not come up with the better way of mocking the repository to test the clearExpiredDeviceCodes(). Could you please help me. |
-with thenReturn() and doAnswer()
-with thenReturn() and doAnswer()
Update TestDefaultDeviceCodeService.java
No description provided.