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

pull/357/merge
William Kim 2013-06-13 09:55:10 -04:00 committed by Justin Richer
parent 01fcb4828d
commit 5428848627
2 changed files with 12 additions and 20 deletions

View File

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

View File

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