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));
- options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2, fcpInterface.new SetFullAccessRequired()));
+ options.addIntegerOption("FcpFullAccessRequired", new DefaultOption<Integer>(2));
loadConfigurationValue("InsertionDelay");
loadConfigurationValue("PostsPerPage");
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent;
import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent;
+import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
import com.google.common.eventbus.EventBus;
*/
public Preferences setFcpFullAccessRequired(FullAccessRequired fcpFullAccessRequired) {
options.getIntegerOption("FcpFullAccessRequired").set((fcpFullAccessRequired != null) ? fcpFullAccessRequired.ordinal() : null);
+ eventBus.post(new FullAccessRequiredChanged(fcpFullAccessRequired));
return this;
}
import net.pterodactylus.sone.core.Options.OptionWatcher;
import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent;
import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent;
+import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
import net.pterodactylus.sone.freenet.fcp.Command.AccessType;
import net.pterodactylus.sone.freenet.fcp.Command.ErrorResponse;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
return fullAccessRequired.get();
}
- /**
- * Sets the action level for which full FCP access is required.
- *
- * @param fullAccessRequired
- * The action level for which full FCP access is required
- */
- public void setFullAccessRequired(FullAccessRequired fullAccessRequired) {
+ private void setFullAccessRequired(FullAccessRequired fullAccessRequired) {
this.fullAccessRequired.set(checkNotNull(fullAccessRequired, "fullAccessRequired must not be null"));
}
setActive(false);
}
- public class SetFullAccessRequired implements OptionWatcher<Integer> {
-
- @Override
- public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
- setFullAccessRequired(FullAccessRequired.values()[newValue]);
- }
-
+ @Subscribe
+ public void fullAccessRequiredChanged(FullAccessRequiredChanged fullAccessRequiredChanged) {
+ setFullAccessRequired(fullAccessRequiredChanged.getFullAccessRequired());
}
}
--- /dev/null
+package net.pterodactylus.sone.fcp.event;
+
+import net.pterodactylus.sone.fcp.FcpInterface;
+import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
+
+/**
+ * Event that signals that the {@link FcpInterface}’s {@link
+ * FullAccessRequired} parameter was changed in the configuration.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class FullAccessRequiredChanged {
+
+ private final FullAccessRequired fullAccessRequired;
+
+ public FullAccessRequiredChanged(FullAccessRequired fullAccessRequired) {
+ this.fullAccessRequired = fullAccessRequired;
+ }
+
+ public FullAccessRequired getFullAccessRequired() {
+ return fullAccessRequired;
+ }
+
+}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent;
import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent;
+import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
import com.google.common.eventbus.EventBus;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
/**
* Unit test for {@link Preferences}.
verify(integerOption).set(null);
}
+ @Test
+ public void settingFcpFullAccessRequiredIsForwardedToEventBus() {
+ preferences.setFcpFullAccessRequired(ALWAYS);
+ verify(integerOption).set(2);
+ ArgumentCaptor<FullAccessRequiredChanged> fullAccessRequiredChangedCaptor = forClass(FullAccessRequiredChanged.class);
+ verify(eventBus).post(fullAccessRequiredChangedCaptor.capture());
+ assertThat(fullAccessRequiredChangedCaptor.getValue().getFullAccessRequired(), is(ALWAYS));
+ }
+
}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import net.pterodactylus.sone.fcp.FcpInterface.SetFullAccessRequired;
import net.pterodactylus.sone.fcp.event.FcpInterfaceActivatedEvent;
import net.pterodactylus.sone.fcp.event.FcpInterfaceDeactivatedEvent;
+import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
import org.junit.Test;
public class FcpInterfaceTest {
private final FcpInterface fcpInterface = new FcpInterface(null);
- private final SetFullAccessRequired setFullAccessRequired = fcpInterface.new SetFullAccessRequired();
@Test
public void fcpInterfaceCanBeActivated() {
@Test
public void setFullAccessRequiredCanSetAccessToNo() {
- setFullAccessRequired.optionChanged(null, null, 0);
+ fcpInterface.fullAccessRequiredChanged(
+ new FullAccessRequiredChanged(NO));
assertThat(fcpInterface.getFullAccessRequired(), is(NO));
}
@Test
public void setFullAccessRequiredCanSetAccessToWriting() {
- setFullAccessRequired.optionChanged(null, null, 1);
+ fcpInterface.fullAccessRequiredChanged(
+ new FullAccessRequiredChanged(WRITING));
assertThat(fcpInterface.getFullAccessRequired(), is(WRITING));
}
@Test
public void setFullAccessRequiredCanSetAccessToAlways() {
- setFullAccessRequired.optionChanged(null, null, 2);
+ fcpInterface.fullAccessRequiredChanged(
+ new FullAccessRequiredChanged(ALWAYS));
assertThat(fcpInterface.getFullAccessRequired(), is(ALWAYS));
}