Skip to content

Commit

Permalink
Merge branch 'main' into snyk-upgrade-6da627955d0b789d8be4dccde7e58bf7
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae authored Oct 23, 2024
2 parents 1b8d04f + a9a4bd3 commit 356ec0e
Showing 1 changed file with 39 additions and 0 deletions.
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);}
);
}

}

0 comments on commit 356ec0e

Please sign in to comment.