removed test constructors for DefaultBlacklistedSiteService.java. Used annotation method of injecting mock objects into testing class (@InjectMocks).

pull/357/merge
William Kim 12 years ago committed by Justin Richer
parent 9a3625ae2b
commit 01fcb4828d

@ -41,24 +41,6 @@ public class DefaultBlacklistedSiteService implements BlacklistedSiteService {
@Autowired @Autowired
private BlacklistedSiteRepository repository; private BlacklistedSiteRepository repository;
/**
* Default Constructor
*/
public DefaultBlacklistedSiteService()
{
}
/**
* Constructor for test harness.
*
* @param repository
*/
public DefaultBlacklistedSiteService(BlacklistedSiteRepository repository)
{
this.repository = repository;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.mitre.openid.connect.service.BlacklistedSiteService#getAll() * @see org.mitre.openid.connect.service.BlacklistedSiteService#getAll()
*/ */

@ -22,9 +22,14 @@ 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.openid.connect.model.BlacklistedSite; import org.mitre.openid.connect.model.BlacklistedSite;
import org.mitre.openid.connect.repository.BlacklistedSiteRepository; import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -33,6 +38,7 @@ import com.google.common.collect.Sets;
* @author wkim * @author wkim
* *
*/ */
@RunWith(MockitoJUnitRunner.class)
public class TestDefaultBlacklistedSiteService { public class TestDefaultBlacklistedSiteService {
private BlacklistedSite site1; private BlacklistedSite site1;
@ -42,9 +48,13 @@ public class TestDefaultBlacklistedSiteService {
private String uri2 = "black2"; private String uri2 = "black2";
private String uri3 = "not-black"; private String uri3 = "not-black";
private Set<BlacklistedSite> blackListedSitesSet;
@Mock
private BlacklistedSiteRepository mockRepository; private BlacklistedSiteRepository mockRepository;
private DefaultBlacklistedSiteService service; @InjectMocks
private DefaultBlacklistedSiteService service = new DefaultBlacklistedSiteService();
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
@ -58,12 +68,7 @@ public class TestDefaultBlacklistedSiteService {
site1.setUri(uri1); site1.setUri(uri1);
site2.setUri(uri2); site2.setUri(uri2);
Set<BlacklistedSite> blackListedSitesSet = Sets.newHashSet(site1, site2); blackListedSitesSet = Sets.newHashSet(site1, site2);
mockRepository = Mockito.mock(BlacklistedSiteRepository.class);
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
service = new DefaultBlacklistedSiteService(mockRepository);
} }
/** /**
@ -72,6 +77,8 @@ public class TestDefaultBlacklistedSiteService {
@Test @Test
public void isBlacklisted_yes() { public void isBlacklisted_yes() {
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
assertTrue(service.isBlacklisted(uri1)); assertTrue(service.isBlacklisted(uri1));
assertTrue(service.isBlacklisted(uri2)); assertTrue(service.isBlacklisted(uri2));
@ -84,6 +91,8 @@ public class TestDefaultBlacklistedSiteService {
@Test @Test
public void isBlacklisted_no() { public void isBlacklisted_no() {
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
assertFalse(service.isBlacklisted(uri3)); assertFalse(service.isBlacklisted(uri3));
Mockito.verify(mockRepository).getAll(); Mockito.verify(mockRepository).getAll();

Loading…
Cancel
Save