diff --git a/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java b/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java index f9b5bad5..24a20cfc 100755 --- a/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java +++ b/ipscan-unittest/src/net/azib/ipscan/fetchers/FetcherRegistryImplTest.java @@ -6,29 +6,40 @@ package net.azib.ipscan.fetchers; import static org.junit.Assert.*; import java.util.Iterator; +import java.util.prefs.Preferences; +import org.junit.After; import org.junit.Before; import org.junit.Test; - /** * @author Anton Keks */ public class FetcherRegistryImplTest { + private Preferences preferences; + private Fetcher ipFetcher; private HostnameFetcher hostnameFetcher; private CommentFetcher commentFetcher; private FetcherRegistry fetcherRegistry; @Before - public void setUp() { + public void setUp() throws Exception { + preferences = Preferences.userRoot().node("ipscan-test"); + preferences.clear(); + ipFetcher = new IPFetcher(); hostnameFetcher = new HostnameFetcher(); commentFetcher = new CommentFetcher(); - fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}); + fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}, preferences); } + @After + public void tearDown() throws Exception { + preferences.removeNode(); + } + @Test public void testCreate() throws Exception { assertEquals(3, fetcherRegistry.getRegisteredFetchers().size()); @@ -48,6 +59,20 @@ public class FetcherRegistryImplTest { assertEquals(-1, fetcherRegistry.getSelectedFetcherIndex("blah-blah")); } + @Test + public void testLoadPreferences() throws Exception { + preferences.remove(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS); + fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}, preferences); + assertEquals(3, fetcherRegistry.getSelectedFetchers().size()); + + preferences.put(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS, hostnameFetcher.getLabel() + "###" + commentFetcher.getLabel()); + fetcherRegistry = new FetcherRegistryImpl(new Fetcher[] {ipFetcher, hostnameFetcher, commentFetcher}, preferences); + assertEquals(2, fetcherRegistry.getSelectedFetchers().size()); + Iterator iterator = fetcherRegistry.getSelectedFetchers().iterator(); + assertSame(hostnameFetcher, iterator.next()); + assertSame(commentFetcher, iterator.next()); + } + @Test public void testUpdateSelectedFetchers() throws Exception { // retain only one selected fetcher @@ -55,6 +80,7 @@ public class FetcherRegistryImplTest { assertEquals(1, fetcherRegistry.getSelectedFetchers().size()); Iterator iterator = fetcherRegistry.getSelectedFetchers().iterator(); assertEquals(ipFetcher.getLabel(), ((Fetcher)iterator.next()).getLabel()); + assertEquals(ipFetcher.getLabel(), preferences.get(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS, null)); // now return a fetcher back fetcherRegistry.updateSelectedFetchers(new String[] {commentFetcher.getLabel(), ipFetcher.getLabel()}); @@ -62,6 +88,7 @@ public class FetcherRegistryImplTest { iterator = fetcherRegistry.getSelectedFetchers().iterator(); assertEquals(commentFetcher.getLabel(), ((Fetcher)iterator.next()).getLabel()); assertEquals(ipFetcher.getLabel(), ((Fetcher)iterator.next()).getLabel()); + assertEquals(commentFetcher.getLabel() + "###" + ipFetcher.getLabel(), preferences.get(FetcherRegistryImpl.PREFERENCE_SELECTED_FETCHERS, null)); } @Test