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;
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;
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");
this.active = active;
}
+ @VisibleForTesting
+ FullAccessRequired getFullAccessRequired() {
+ return fullAccessRequired;
+ }
+
/**
* Sets the action level for which full FCP access is required.
*
}
+ public class SetFullAccessRequired implements OptionWatcher<Integer> {
+
+ @Override
+ public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
+ setFullAccessRequired(FullAccessRequired.values()[newValue]);
+ }
+
+ }
+
}
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;
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() {
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));
+ }
+
}