Browse Source

updated TestDefaultApprovedSiteService to use annotation style Mocking. Allows for removal of injector constructor.

pull/357/merge
William Kim 12 years ago committed by Justin Richer
parent
commit
5428848627
  1. 16
      openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultApprovedSiteService.java
  2. 14
      openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestDefaultApprovedSiteService.java

16
openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultApprovedSiteService.java

@ -42,22 +42,6 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
@Autowired
private ApprovedSiteRepository approvedSiteRepository;
/**
* Default constructor
*/
public DefaultApprovedSiteService() {
}
/**
* Constructor for use in test harnesses.
*
* @param repository
*/
public DefaultApprovedSiteService(ApprovedSiteRepository approvedSiteRepository) {
this.approvedSiteRepository = approvedSiteRepository;
}
@Override
public Collection<ApprovedSite> getAll() {
return approvedSiteRepository.getAll();

14
openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestDefaultApprovedSiteService.java

@ -9,15 +9,20 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mitre.oauth2.model.ClientDetailsEntity;
import org.mitre.openid.connect.model.ApprovedSite;
import org.mitre.openid.connect.repository.ApprovedSiteRepository;
import org.mitre.openid.connect.service.ApprovedSiteService;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.annotation.Rollback;
import com.google.common.collect.Sets;
@RunWith(MockitoJUnitRunner.class)
public class TestDefaultApprovedSiteService {
private ApprovedSite site1;
@ -27,9 +32,13 @@ public class TestDefaultApprovedSiteService {
private ClientDetailsEntity client;
private final String clientId = "client";
private ApprovedSiteService service;
@Mock
private ApprovedSiteRepository repository;
@InjectMocks
private ApprovedSiteService service = new DefaultApprovedSiteService();
/**
* Initialize the service and repository mock. Initialize a client and
* several ApprovedSite objects for use in unit tests.
@ -55,9 +64,8 @@ public class TestDefaultApprovedSiteService {
site3.setUserId("user2");
site3.setClientId(clientId);
repository = Mockito.mock(ApprovedSiteRepository.class);
Mockito.reset(repository);
service = new DefaultApprovedSiteService(repository);
}
/**

Loading…
Cancel
Save