X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Futil%2Fdialogrunner%2FDialogRunnerTest.java;h=702601c81f407d780447ceca14ab1f4d630d797f;hb=6ca8a32d88328b8f2162512f41c657c87e131045;hp=e69ae878acac372995879bafb6da6b1f4e09969d;hpb=be9359e9a28efb6aade9bdac054d76b4f9452c47;p=jalview.git
diff --git a/test/jalview/util/dialogrunner/DialogRunnerTest.java b/test/jalview/util/dialogrunner/DialogRunnerTest.java
index e69ae87..702601c 100644
--- a/test/jalview/util/dialogrunner/DialogRunnerTest.java
+++ b/test/jalview/util/dialogrunner/DialogRunnerTest.java
@@ -1,129 +1,25 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.util.dialogrunner;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
public class DialogRunnerTest
{
- public class MockDialog implements DialogRunnerI
- {
- DialogRunner runner = new DialogRunner<>(this);
-
- @Override
- public MockDialog response(RunResponse action)
- {
- return runner.response(action);
- }
-
- public void doDialog(String resp)
- {
- runner.firstRun(resp);
- }
- }
-
- MockDialog dialog = new MockDialog();
-
- @Test
- public void testDialogRunner()
- {
- RunResponse ok, cancel, help, ineed;
- final Response ooh = new Response("OOOOoooOOOOH!"),
- r_ok = new Response("OK"), r_cancel = new Response("CANCEL"),
- r_done = new Response("DONE"), r_help = new Response("HELP"),
- r_ddoit = new Response("DIDNT DOIT"),
- r_needsb = new Response("I NEED SOMEBODY");
-
- ok = new RunResponse("OK")
- {
-
- @Override
- public void run()
- {
- returned = new Response("DONE");
- }
- };
- final RunResponse befok = new RunResponse("OK")
- {
-
- @Override
- public void run()
- {
- returned = new Response("OK");
- }
- };
-
- cancel = new RunResponse("CANCEL")
- {
- @Override
- public void run()
- {
- returned = r_ddoit;
- }
- };
- help = new RunResponse("HELP")
- {
- @Override
- public void run()
- {
- returned = r_needsb;
-
- }
- };
- ineed = new RunResponse(r_needsb)
- {
- @Override
- public void run()
- {
- returned = ooh;
- }
- };
-
- Assert.assertFalse(dialog.runner.isRegistered(ok));
-
- dialog.response(ok).response(cancel).response(help).response(ineed);
-
- Assert.assertTrue(dialog.runner.isRegistered(ok));
-
- Assert.assertFalse(dialog.runner.firstRunWasCalled);
- dialog.doDialog("OK");
- // OK called, nothing else.
- Assert.assertTrue(dialog.runner.firstRunWasCalled);
- Assert.assertTrue(ok.wasRun);
- Assert.assertEquals(ok.returned, r_done);
- Assert.assertFalse(cancel.wasRun);
- Assert.assertEquals(dialog.runner.responses.size(), 2);
-
- // do it again - check it doesn't trigger again
- ok.wasRun = false;
- dialog.doDialog("OK");
- Assert.assertFalse(ok.wasRun);
-
- // reset - everything false/null
- dialog.runner.resetResponses();
- Assert.assertFalse(dialog.runner.firstRunWasCalled);
- Assert.assertFalse(ok.wasRun);
- Assert.assertNull(ok.returned);
- Assert.assertEquals(dialog.runner.responses.size(), 0);
-
- // cancel called ..
- dialog.doDialog("HELP");
- Assert.assertTrue(dialog.runner.firstRunWasCalled);
- Assert.assertFalse(ok.wasRun);
- Assert.assertEquals(ineed.returned, ooh);
- Assert.assertEquals(dialog.runner.responses.size(), 3);
-
- // TODO: test prepend and chained execution of tasks for a response.
- Assert.assertFalse(dialog.runner.isRegistered(befok));
- dialog.runner.firstResponse(befok);
-
- Assert.assertTrue(dialog.runner.isRegistered(befok));
- Assert.assertTrue(dialog.runner.isRegistered(ok));
-
- dialog.runner.resetResponses();
-
- dialog.doDialog("OK");
- Assert.assertTrue(befok.wasRun);
- Assert.assertTrue(ok.wasRun);
- Assert.assertEquals(dialog.runner.responses.size(), 3);
- }
}