-
Notifications
You must be signed in to change notification settings - Fork 148
[MOSIP-42804] - Sonar coverage added for admin-services #1345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
517ea9d
[MOSIP-42804] - Sonar coverage added
NidhiKumari0201 8139b9b
[MOSIP-42804] - Sonar coverage added
NidhiKumari0201 56ad49f
[MOSIP-42804] - added more coverage
NidhiKumari0201 28e95d1
[MOSIP-42804] - code rabbit comments fixed
NidhiKumari0201 ac822a5
[MOSIP-42804] - code rabbit comments fixed
NidhiKumari0201 5bb511c
[MOSIP-42804] - added test case
NidhiKumari0201 e72b6e0
[MOSIP-42804] - added test case
NidhiKumari0201 4656e08
[MOSIP-42804] - added test case
NidhiKumari0201 cdd4572
[MOSIP-42804] - added test case
NidhiKumari0201 1c1ad29
[MOSIP-42804] - added test case
NidhiKumari0201 21137d8
[MOSIP-42804] - coderabbit comment fix
NidhiKumari0201 1c69e2d
[MOSIP-42804] - coderabbit comment fix
NidhiKumari0201 a1820dc
MOSIP-42804: Move SyncMasterDataServiceHelperTest to util package
NidhiKumari0201 7a776be
MOSIP-42804: RestHelper coverage added
NidhiKumari0201 c48bb55
MOSIP-42804: RestHelper coverage added
NidhiKumari0201 a901812
MOSIP-42804: coverage added for SyncMasterDataServiceHelper
NidhiKumari0201 e2c9150
MOSIP-42804: code rabbit comment fix
NidhiKumari0201 f9f4930
MOSIP-42804: code rabbit comment fix
NidhiKumari0201 9d2dd43
MOSIP-42804: review comment resolved
NidhiKumari0201 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...est/java/io/mosip/kernel/masterdata/test/service/impl/CacheManagementServiceImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package io.mosip.kernel.masterdata.test.service.impl; | ||
|
|
||
| import io.mosip.kernel.masterdata.service.impl.CacheManagementServiceImpl; | ||
| import io.mosip.kernel.masterdata.utils.CacheName; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.springframework.cache.Cache; | ||
| import org.springframework.cache.CacheManager; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| class CacheManagementServiceImplTest { | ||
|
|
||
| @InjectMocks | ||
| private CacheManagementServiceImpl cacheService; | ||
|
|
||
| @Mock | ||
| private CacheManager cacheManager; | ||
|
|
||
| @Mock | ||
| private Cache mockCache1; | ||
|
|
||
| @Mock | ||
| private Cache mockCache2; | ||
|
|
||
| @BeforeEach | ||
| void setup() { | ||
| MockitoAnnotations.openMocks(this); | ||
| } | ||
|
|
||
| @Test | ||
| void clearCacheByCacheName_existingCache_clearsOnlyMatched() { | ||
| when(cacheManager.getCacheNames()).thenReturn(Arrays.asList("blocklisted-words", "other-cache")); | ||
| when(cacheManager.getCache("blocklisted-words")).thenReturn(mockCache1); | ||
| when(cacheManager.getCache("other-cache")).thenReturn(mockCache2); | ||
|
|
||
| cacheService.clearCacheByCacheName(CacheName.BLOCK_LISTED_WORDS); | ||
|
|
||
| verify(mockCache1).clear(); | ||
| verify(mockCache2, never()).clear(); | ||
| } | ||
|
|
||
| @Test | ||
| void clearCacheByCacheName_cacheNotFound_doesNotThrow() { | ||
| when(cacheManager.getCacheNames()).thenReturn(Collections.singletonList("CACHE2")); | ||
| when(cacheManager.getCache("CACHE2")).thenReturn(mockCache2); | ||
|
|
||
| assertDoesNotThrow(() -> cacheService.clearCacheByCacheName(CacheName.BLOCK_LISTED_WORDS)); | ||
|
|
||
| verify(mockCache2, never()).clear(); | ||
| } | ||
|
|
||
| @Test | ||
| void clearCacheByCacheName_nullCache_ignored() { | ||
| when(cacheManager.getCacheNames()).thenReturn(Collections.singletonList("CACHE1")); | ||
| when(cacheManager.getCache("CACHE1")).thenReturn(null); | ||
|
|
||
| assertDoesNotThrow(() -> cacheService.clearCacheByCacheName(CacheName.BLOCK_LISTED_WORDS)); | ||
| } | ||
|
|
||
| @Test | ||
| void clearCache_clearsAllCaches() { | ||
| when(cacheManager.getCacheNames()).thenReturn(Arrays.asList("CACHE1", "CACHE2")); | ||
| when(cacheManager.getCache("CACHE1")).thenReturn(mockCache1); | ||
| when(cacheManager.getCache("CACHE2")).thenReturn(mockCache2); | ||
|
|
||
| cacheService.clearCache(); | ||
|
|
||
| verify(mockCache1).clear(); | ||
| verify(mockCache2).clear(); | ||
| } | ||
|
|
||
| @Test | ||
| void clearCache_nullCaches_ignored() { | ||
| when(cacheManager.getCacheNames()).thenReturn(Arrays.asList("CACHE1", "CACHE2")); | ||
| when(cacheManager.getCache("CACHE1")).thenReturn(null); | ||
| when(cacheManager.getCache("CACHE2")).thenReturn(mockCache2); | ||
|
|
||
| cacheService.clearCache(); | ||
|
|
||
| verify(mockCache2).clear(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.