Add method to add wait time for reloading plugins
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 20:43:34 +0000 (22:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 20:44:51 +0000 (22:44 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index ef25380..65febba 100644 (file)
@@ -11,6 +11,7 @@ import net.pterodactylus.fcp.PluginInfo;
  */
 public interface ReloadPluginCommand {
 
+       ReloadPluginCommand waitFor(int milliseconds);
        Executable<Optional<PluginInfo>> plugin(String pluginClassName);
 
 }
index c1a33fe..f7c11a9 100644 (file)
@@ -33,6 +33,12 @@ public class ReloadPluginCommandImpl implements ReloadPluginCommand {
        }
 
        @Override
+       public ReloadPluginCommand waitFor(int milliseconds) {
+               reloadPlugin.setMaxWaitTime(milliseconds);
+               return this;
+       }
+
+       @Override
        public Executable<Optional<PluginInfo>> plugin(String pluginClassName) {
                reloadPlugin.setPluginName(pluginClassName);
                return this::execute;
index 7ba009c..d4d67c5 100644 (file)
@@ -1,6 +1,7 @@
 package net.pterodactylus.fcp.quelaton;
 
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.hasItem;
@@ -2145,14 +2146,28 @@ public class DefaultFcpClientTest {
                        @Test
                        public void reloadingPluginWorks() throws InterruptedException, ExecutionException, IOException {
                                Future<Optional<PluginInfo>> pluginInfo = fcpClient.reloadPlugin().plugin(CLASS_NAME).execute();
-                               connectAndAssert(() -> matchesFcpMessage(
+                               connectAndAssert(() -> matchReloadPluginMessage());
+                               replyWithPluginInfo();
+                               verifyPluginInfo(pluginInfo);
+                       }
+
+                       @Test
+                       public void reloadingPluginWithMaxWaitTimeWorks()
+                       throws InterruptedException, ExecutionException, IOException {
+                               Future<Optional<PluginInfo>> pluginInfo =
+                                       fcpClient.reloadPlugin().waitFor(1234).plugin(CLASS_NAME).execute();
+                               connectAndAssert(() -> allOf(matchReloadPluginMessage(), hasItem("MaxWaitTime=1234")));
+                               replyWithPluginInfo();
+                               verifyPluginInfo(pluginInfo);
+                       }
+
+                       private Matcher<List<String>> matchReloadPluginMessage() {
+                               return matchesFcpMessage(
                                        "ReloadPlugin",
                                        "Identifier=" + identifier,
                                        "PluginName=" + CLASS_NAME,
                                        "EndMessage"
-                               ));
-                               replyWithPluginInfo();
-                               verifyPluginInfo(pluginInfo);
+                               );
                        }
 
                }