From 6282ab82c0e14ae7dea70ada2fa5e08570280f1a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 29 Jul 2014 19:58:16 +0200 Subject: [PATCH] Add class to set FCP interface access level from an option. --- .../java/net/pterodactylus/sone/core/Core.java | 14 +------------ .../net/pterodactylus/sone/fcp/FcpInterface.java | 14 +++++++++++++ .../pterodactylus/sone/fcp/FcpInterfaceTest.java | 23 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 4ee0258..c9ac93b 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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(-25, new IntegerRangePredicate(-100, 100))); options.addStringOption("TrustComment", new DefaultOption("Set from Sone Web Interface")); options.addBooleanOption("ActivateFcpInterface", new DefaultOption(false, fcpInterface.new SetActive())); - options.addIntegerOption("FcpFullAccessRequired", new DefaultOption(2, new OptionWatcher() { - - @Override - @SuppressWarnings("synthetic-access") - public void optionChanged(Option option, Integer oldValue, Integer newValue) { - fcpInterface.setFullAccessRequired(FullAccessRequired.values()[newValue]); - } - - })); + options.addIntegerOption("FcpFullAccessRequired", new DefaultOption(2, fcpInterface.new SetFullAccessRequired())); loadConfigurationValue("InsertionDelay"); loadConfigurationValue("PostsPerPage"); diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index c71fd82..18c017b 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -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 { + + @Override + public void optionChanged(Option option, Integer oldValue, Integer newValue) { + setFullAccessRequired(FullAccessRequired.values()[newValue]); + } + + } + } diff --git a/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java index 6ecd687..2c8a910 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/FcpInterfaceTest.java @@ -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)); + } + } -- 2.7.4