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.core.event.MarkPostReplyKnownEvent;
*/
private void loadConfiguration() {
/* create options. */
- options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new IntegerRangePredicate(0, Integer.MAX_VALUE), new OptionWatcher<Integer>() {
-
- @Override
- public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
- SoneInserter.setInsertionDelay(newValue);
- }
-
- }));
+ options.addIntegerOption("InsertionDelay", new DefaultOption<Integer>(60, new IntegerRangePredicate(0, Integer.MAX_VALUE), new SetInsertionDelay()));
options.addIntegerOption("PostsPerPage", new DefaultOption<Integer>(10, new IntegerRangePredicate(1, Integer.MAX_VALUE)));
options.addIntegerOption("ImagesPerPage", new DefaultOption<Integer>(9, new IntegerRangePredicate(1, Integer.MAX_VALUE)));
options.addIntegerOption("CharactersPerPost", new DefaultOption<Integer>(400, Predicates.<Integer> or(new IntegerRangePredicate(50, Integer.MAX_VALUE), Predicates.equalTo(-1))));
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.sone.core.Options.Option;
+import net.pterodactylus.sone.core.Options.OptionWatcher;
import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
import net.pterodactylus.sone.core.event.SoneInsertedEvent;
import net.pterodactylus.sone.core.event.SoneInsertingEvent;
import net.pterodactylus.util.template.TemplateParser;
import net.pterodactylus.util.template.XmlFilter;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Ordering;
import com.google.common.eventbus.EventBus;
return this;
}
+ @VisibleForTesting
+ static AtomicInteger getInsertionDelay() {
+ return insertionDelay;
+ }
+
/**
* Changes the insertion delay, i.e. the time the Sone inserter waits after it
* has noticed a Sone modification before it starts the insert.
}
}
+ static class SetInsertionDelay implements OptionWatcher<Integer> {
+
+ @Override
+ public void optionChanged(Option<Integer> option, Integer oldValue, Integer newValue) {
+ setInsertionDelay(newValue);
+ }
+
+ }
+
/**
* Container for information that are required to insert a Sone. This
* container merely exists to copy all relevant data without holding a lock
--- /dev/null
+package net.pterodactylus.sone.core;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import net.pterodactylus.sone.core.SoneInserter.SetInsertionDelay;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link SoneInserter} and its subclasses.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneInserterTest {
+
+ @Test
+ public void insertionDelayIsForwardedToSoneInserter() {
+ SetInsertionDelay setInsertionDelay = new SetInsertionDelay();
+ setInsertionDelay.optionChanged(null, null, 15);
+ assertThat(SoneInserter.getInsertionDelay().get(), is(15));
+ }
+
+}