Added comments to unit tests
parent
a7f2e605fa
commit
3f7fe30f5c
|
@ -30,6 +30,10 @@ public class TestDefaultApprovedSiteService {
|
|||
private ApprovedSiteService service;
|
||||
private ApprovedSiteRepository repository;
|
||||
|
||||
/**
|
||||
* Initialize the service and repository mock. Initialize a client and
|
||||
* several ApprovedSite objects for use in unit tests.
|
||||
*/
|
||||
@Before
|
||||
public void prepare() {
|
||||
|
||||
|
@ -56,6 +60,10 @@ public class TestDefaultApprovedSiteService {
|
|||
service = new DefaultApprovedSiteService(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing approved sites for a client that has 2 stored approved sites.
|
||||
* Ensure that the repository's remove() method is called twice.
|
||||
*/
|
||||
@Test
|
||||
public void clearApprovedSitesForClient_success() {
|
||||
Set<ApprovedSite> setToReturn = Sets.newHashSet(site2, site3);
|
||||
|
@ -66,6 +74,10 @@ public class TestDefaultApprovedSiteService {
|
|||
Mockito.verify(repository, times(2)).remove(any(ApprovedSite.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test clearing approved sites for a client that doesn't have any stored approved
|
||||
* sites. Ensure that the repository's remove() method is never called in this case.
|
||||
*/
|
||||
@Test
|
||||
@Rollback
|
||||
public void clearApprovedSitesForClient_null() {
|
||||
|
|
|
@ -30,6 +30,10 @@ public class TestDefaultUserInfoUserDetailsService {
|
|||
private String adminSub = "adminSub12d3a1f34a2";
|
||||
private String regularSub = "regularSub652ha23b";
|
||||
|
||||
/**
|
||||
* Initialize the service and the mocked repository.
|
||||
* Initialize 2 users, one of them an admin, for use in unit tests.
|
||||
*/
|
||||
@Before
|
||||
public void prepare() {
|
||||
userInfoRepository = Mockito.mock(UserInfoRepository.class);
|
||||
|
@ -45,6 +49,10 @@ public class TestDefaultUserInfoUserDetailsService {
|
|||
userInfoRegular.setSub(regularSub);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test loading an admin user, ensuring that the UserDetails object returned
|
||||
* has both the ROLE_USER and ROLE_ADMIN authorities.
|
||||
*/
|
||||
@Test
|
||||
public void loadByUsername_admin_success() {
|
||||
|
||||
|
@ -57,6 +65,10 @@ public class TestDefaultUserInfoUserDetailsService {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test loading a regular, non-admin user, ensuring that the returned UserDetails
|
||||
* object has ROLE_USER but *not* ROLE_ADMIN.
|
||||
*/
|
||||
@Test
|
||||
public void loadByUsername_regular_success() {
|
||||
|
||||
|
@ -69,6 +81,9 @@ public class TestDefaultUserInfoUserDetailsService {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* If a user is not found, the loadByUsername method should throw an exception.
|
||||
*/
|
||||
@Test(expected = UsernameNotFoundException.class)
|
||||
public void loadByUsername_nullUser() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue