JAL-3954 Implement NullAction and NullTask for testing purposes
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 10 May 2023 09:22:28 +0000 (11:22 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 10 May 2023 09:22:28 +0000 (11:22 +0200)
src/jalview/ws2/actions/NullAction.java [new file with mode: 0644]
src/jalview/ws2/actions/NullTask.java [new file with mode: 0644]

diff --git a/src/jalview/ws2/actions/NullAction.java b/src/jalview/ws2/actions/NullAction.java
new file mode 100644 (file)
index 0000000..655a133
--- /dev/null
@@ -0,0 +1,52 @@
+package jalview.ws2.actions;
+
+import java.util.List;
+
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.params.ArgumentI;
+import jalview.ws2.actions.api.ActionI;
+import jalview.ws2.actions.api.TaskEventListener;
+import jalview.ws2.actions.api.TaskI;
+import jalview.ws2.api.Credentials;
+
+/**
+ * An empty implementation of the {@link ActionI} interface that does nothing.
+ * Use as a placeholder for testing purposes.
+ * 
+ * @author mmwarowny
+ *
+ */
+public final class NullAction extends BaseAction<Void>
+{
+  public static final class Builder extends BaseAction.Builder<NullAction>
+  {
+    public NullAction build()
+    {
+      return new NullAction(this);
+    }
+  }
+  
+  public static Builder newBuilder()
+  {
+    return new Builder();
+  }
+  
+  protected NullAction(Builder builder)
+  {
+    super(builder);
+  }
+
+  @Override
+  public TaskI<Void> perform(AlignmentViewport viewport,
+          List<ArgumentI> args, Credentials credentials,
+          TaskEventListener<Void> handler)
+  {
+    return new NullTask();
+  }
+
+  @Override
+  public boolean isActive(AlignmentViewport viewport)
+  {
+    return false;
+  }
+}
diff --git a/src/jalview/ws2/actions/NullTask.java b/src/jalview/ws2/actions/NullTask.java
new file mode 100644 (file)
index 0000000..223b9fb
--- /dev/null
@@ -0,0 +1,47 @@
+package jalview.ws2.actions;
+
+import java.util.Collections;
+import java.util.List;
+
+import jalview.ws2.actions.api.JobI;
+import jalview.ws2.actions.api.TaskI;
+import jalview.ws2.api.JobStatus;
+
+/**
+ * An empty task returned by the {@link NullAction}. Use as a placeholder
+ * for testing purposes.
+ * 
+ * @author mmwarowny
+ *
+ */
+class NullTask implements TaskI<Void>
+{
+  @Override
+  public long getUid()
+  {
+    return 0;
+  }
+
+  @Override
+  public JobStatus getStatus()
+  {
+    return JobStatus.READY;
+  }
+
+  @Override
+  public List<? extends JobI> getSubJobs()
+  {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public Void getResult()
+  {
+    return null;
+  }
+
+  @Override
+  public void cancel()
+  {
+  }
+}
\ No newline at end of file