Add class to set FCP interface access level from an option.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 29 Jul 2014 17:58:16 +0000 (19:58 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 29 Jul 2014 17:58:16 +0000 (19:58 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java
src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java

index 4ee0258..c9ac93b 100644 (file)
@@ -39,8 +39,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Options.DefaultOption;
-import net.pterodactylus.sone.core.Options.Option;
-import net.pterodactylus.sone.core.Options.OptionWatcher;
 import net.pterodactylus.sone.core.SoneInserter.SetInsertionDelay;
 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
@@ -75,8 +73,6 @@ import net.pterodactylus.sone.database.PostReplyBuilder;
 import net.pterodactylus.sone.database.PostReplyProvider;
 import net.pterodactylus.sone.database.SoneProvider;
 import net.pterodactylus.sone.fcp.FcpInterface;
-import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
-import net.pterodactylus.sone.fcp.FcpInterface.SetActive;
 import net.pterodactylus.sone.freenet.wot.Identity;
 import net.pterodactylus.sone.freenet.wot.IdentityManager;
 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
@@ -2000,15 +1996,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                options.addIntegerOption("NegativeTrust", new DefaultOption<Integer>(-25, new IntegerRangePredicate(-100, 100)));
                options.addStringOption("TrustComment", new DefaultOption<String>("Set from Sone Web Interface"));
                options.addBooleanOption("ActivateFcpInterface", new DefaultOption<Boolean>(false, fcpInterface.new SetActive()));
-               options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2, new OptionWatcher<Integer>() {
-
-                       @Override
-                       @SuppressWarnings("synthetic-access")
-                       public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
-                               fcpInterface.setFullAccessRequired(FullAccessRequired.values()[newValue]);
-                       }
-
-               }));
+               options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2, fcpInterface.new SetFullAccessRequired()));
 
                loadConfigurationValue("InsertionDelay");
                loadConfigurationValue("PostsPerPage");
index c71fd82..18c017b 100644 (file)
@@ -126,6 +126,11 @@ public class FcpInterface {
                this.active = active;
        }
 
+       @VisibleForTesting
+       FullAccessRequired getFullAccessRequired() {
+               return fullAccessRequired;
+       }
+
        /**
         * Sets the action level for which full FCP access is required.
         *
@@ -233,4 +238,13 @@ public class FcpInterface {
 
        }
 
+       public class SetFullAccessRequired implements OptionWatcher<Integer> {
+
+               @Override
+               public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
+                       setFullAccessRequired(FullAccessRequired.values()[newValue]);
+               }
+
+       }
+
 }
index 6ecd687..2c8a910 100644 (file)
@@ -1,9 +1,13 @@
 package net.pterodactylus.sone.fcp;
 
+import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.ALWAYS;
+import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO;
+import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
 import net.pterodactylus.sone.fcp.FcpInterface.SetActive;
+import net.pterodactylus.sone.fcp.FcpInterface.SetFullAccessRequired;
 
 import org.junit.Test;
 
@@ -16,6 +20,7 @@ public class FcpInterfaceTest {
 
        private final FcpInterface fcpInterface = new FcpInterface(null);
        private final SetActive setActive = fcpInterface.new SetActive();
+       private final SetFullAccessRequired setFullAccessRequired = fcpInterface.new SetFullAccessRequired();
 
        @Test
        public void setActiveCanActivateFcpInterface() {
@@ -29,4 +34,22 @@ public class FcpInterfaceTest {
                assertThat(fcpInterface.isActive(), is(false));
        }
 
+       @Test
+       public void setFullAccessRequiredCanSetAccessToNo() {
+               setFullAccessRequired.optionChanged(null, null, 0);
+               assertThat(fcpInterface.getFullAccessRequired(), is(NO));
+       }
+
+       @Test
+       public void setFullAccessRequiredCanSetAccessToWriting() {
+               setFullAccessRequired.optionChanged(null, null, 1);
+               assertThat(fcpInterface.getFullAccessRequired(), is(WRITING));
+       }
+
+       @Test
+       public void setFullAccessRequiredCanSetAccessToAlways() {
+               setFullAccessRequired.optionChanged(null, null, 2);
+               assertThat(fcpInterface.getFullAccessRequired(), is(ALWAYS));
+       }
+
 }