-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into snyk-upgrade-4b20f466e87cbecfd4adbd81bf5f6f40
- Loading branch information
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
39 changes: 39 additions & 0 deletions
39
api/src/test/java/gov/cms/ab2d/api/security/CustomUserDetailsServiceTest.java
This file contains 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,39 @@ | ||
package gov.cms.ab2d.api.security; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
|
||
import gov.cms.ab2d.common.model.PdpClient; | ||
import gov.cms.ab2d.common.repository.PdpClientRepository; | ||
|
||
class CustomUserDetailsServiceTest { | ||
|
||
@Test | ||
void testLoadUserByUsername1() { | ||
PdpClientRepository pdpClientRepository = mock(PdpClientRepository.class); | ||
CustomUserDetailsService customUserDetailsService = new CustomUserDetailsService(pdpClientRepository); | ||
PdpClient pdpClient = new PdpClient(); | ||
when(pdpClientRepository.findByClientId("clientId")).thenReturn(pdpClient); | ||
assertEquals( | ||
customUserDetailsService.loadUserByUsername("clientId"), | ||
pdpClient | ||
); | ||
} | ||
|
||
@Test | ||
void testLoadUserByUsername2() { | ||
PdpClientRepository pdpClientRepository = mock(PdpClientRepository.class); | ||
CustomUserDetailsService customUserDetailsService = new CustomUserDetailsService(pdpClientRepository); | ||
when(pdpClientRepository.findByClientId(null)).thenReturn(null); | ||
assertThrows( | ||
UsernameNotFoundException.class, | ||
() -> {customUserDetailsService.loadUserByUsername(null);} | ||
); | ||
} | ||
|
||
} |
This file contains 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