From 01fcb4828d9affc0d64c417d536599f73ce2b7ce Mon Sep 17 00:00:00 2001 From: William Kim Date: Wed, 12 Jun 2013 16:38:46 -0400 Subject: [PATCH] removed test constructors for DefaultBlacklistedSiteService.java. Used annotation method of injecting mock objects into testing class (@InjectMocks). --- .../impl/DefaultBlacklistedSiteService.java | 18 --------------- .../TestDefaultBlacklistedSiteService.java | 23 +++++++++++++------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultBlacklistedSiteService.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultBlacklistedSiteService.java index 02b405b66..cea94da0a 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultBlacklistedSiteService.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultBlacklistedSiteService.java @@ -41,24 +41,6 @@ public class DefaultBlacklistedSiteService implements BlacklistedSiteService { @Autowired private BlacklistedSiteRepository repository; - /** - * Default Constructor - */ - public DefaultBlacklistedSiteService() - { - - } - - /** - * Constructor for test harness. - * - * @param repository - */ - public DefaultBlacklistedSiteService(BlacklistedSiteRepository repository) - { - this.repository = repository; - } - /* (non-Javadoc) * @see org.mitre.openid.connect.service.BlacklistedSiteService#getAll() */ diff --git a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestDefaultBlacklistedSiteService.java b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestDefaultBlacklistedSiteService.java index 822136335..7da845274 100644 --- a/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestDefaultBlacklistedSiteService.java +++ b/openid-connect-server/src/test/java/org/mitre/openid/connect/service/impl/TestDefaultBlacklistedSiteService.java @@ -22,9 +22,14 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mitre.openid.connect.model.BlacklistedSite; import org.mitre.openid.connect.repository.BlacklistedSiteRepository; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + import static org.mockito.Mockito.times; import com.google.common.collect.Sets; @@ -33,6 +38,7 @@ import com.google.common.collect.Sets; * @author wkim * */ +@RunWith(MockitoJUnitRunner.class) public class TestDefaultBlacklistedSiteService { private BlacklistedSite site1; @@ -42,9 +48,13 @@ public class TestDefaultBlacklistedSiteService { private String uri2 = "black2"; private String uri3 = "not-black"; + private Set blackListedSitesSet; + + @Mock private BlacklistedSiteRepository mockRepository; - private DefaultBlacklistedSiteService service; + @InjectMocks + private DefaultBlacklistedSiteService service = new DefaultBlacklistedSiteService(); /** * @throws java.lang.Exception @@ -58,12 +68,7 @@ public class TestDefaultBlacklistedSiteService { site1.setUri(uri1); site2.setUri(uri2); - Set blackListedSitesSet = Sets.newHashSet(site1, site2); - - mockRepository = Mockito.mock(BlacklistedSiteRepository.class); - Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet); - - service = new DefaultBlacklistedSiteService(mockRepository); + blackListedSitesSet = Sets.newHashSet(site1, site2); } /** @@ -72,6 +77,8 @@ public class TestDefaultBlacklistedSiteService { @Test public void isBlacklisted_yes() { + Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet); + assertTrue(service.isBlacklisted(uri1)); assertTrue(service.isBlacklisted(uri2)); @@ -84,6 +91,8 @@ public class TestDefaultBlacklistedSiteService { @Test public void isBlacklisted_no() { + Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet); + assertFalse(service.isBlacklisted(uri3)); Mockito.verify(mockRepository).getAll();