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=b24c599860a921aa819d5d26d3f215d6a44e6ac0;hpb=8e73dcd57f5558b39b3f431667457d78a3cec427;p=jalview.git
diff --git a/test/jalview/util/dialogrunner/DialogRunnerTest.java b/test/jalview/util/dialogrunner/DialogRunnerTest.java
index b24c599..702601c 100644
--- a/test/jalview/util/dialogrunner/DialogRunnerTest.java
+++ b/test/jalview/util/dialogrunner/DialogRunnerTest.java
@@ -1,151 +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 static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.testng.annotations.Test;
-
-import junit.extensions.PA;
-
public class DialogRunnerTest
{
- public class MockDialog implements DialogRunnerI
- {
- DialogRunnerI runner = new DialogRunner();
-
- @Override
- public DialogRunnerI addResponse(Object response, RunResponse action)
- {
- return runner.addResponse(response, action);
- }
-
- public List doDialog(String resp)
- {
- return runner.handleResponse(resp);
- }
-
- @Override
- public List handleResponse(Object response)
- {
- return null;
- }
- }
-
- MockDialog dialog = new MockDialog();
-
- @Test
- public void testDialogRunner()
- {
- RunResponse ok, cancel, help, ineed;
- final String ooh = "OOOOoooOOOOH!";
- final String r_ok = "OK";
- final String r_cancel = "CANCEL";
- final String r_done = "DONE";
- final String r_help = "HELP";
- final String r_ddoit = "DIDNT DOIT";
- final String r_needsb = "I NEED SOMEBODY";
-
- ok = new RunResponse("OK")
- {
- @Override
- public void run()
- {
- returnValue = "DONE";
- }
- };
- final RunResponse befok = new RunResponse("OK")
- {
- @Override
- public void run()
- {
- returnValue = "OK";
- }
- };
-
- cancel = new RunResponse("CANCEL")
- {
- @Override
- public void run()
- {
- returnValue = r_ddoit;
- }
- };
- help = new RunResponse("HELP")
- {
- @Override
- public void run()
- {
- returnValue = r_needsb;
- }
- };
- ineed = new RunResponse(r_needsb)
- {
- @Override
- public void run()
- {
- returnValue = ooh;
- }
- };
-
- assertFalse(isRegistered(dialog.runner, ok));
-
- dialog.addResponse("OK", ok).addResponse("CANCEL", cancel).
- addResponse("HELP", help).addResponse(r_needsb, ineed);
-
- assertTrue(isRegistered(dialog.runner, ok));
-
-// Assert.assertFalse(dialog.runner.firstRunWasCalled);
- List actions = dialog.doDialog("OK");
- // OK called, nothing else.
- // Assert.assertTrue(dialog.runner.firstRunWasCalled);
- assertTrue(actions.contains(ok));//ok.wasRun);
- assertEquals(ok.returnValue, r_done);
- assertFalse(actions.contains(cancel));//cancel.wasRun);
- assertEquals(actions/*dialog.runner.responses*/.size(), 2);
-
- // do it again - check it doesn't trigger again
- //ok.wasRun = false;
- actions = dialog.doDialog("OK");
- assertFalse(actions.contains(ok));
-
- // 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 ..
- actions = dialog.doDialog("HELP");
-// Assert.assertTrue(dialog.runner.firstRunWasCalled);
- assertFalse(actions.contains(ok));//ok.wasRun);
- assertEquals(ineed.returnValue, ooh);
- assertEquals(actions/*dialog.runner.responses*/.size(), 3);
-
- // TODO: test prepend and chained execution of tasks for a response.
-// Assert.assertFalse(dialog.runner.isRegistered(befok));
- dialog.runner.addResponse("OK", befok); //setFirstResponse(befok);
-
- assertTrue(isRegistered(dialog.runner, befok));
- assertTrue(isRegistered(dialog.runner, ok));
-
-// dialog.runner.resetResponses();
-
- actions = dialog.doDialog("OK");
- assertTrue(actions.contains(befok));//befok.wasRun);
- assertTrue(actions.contains(ok)); //ok.wasRun);
- assertEquals(actions/*dialog.runner.responses*/.size(), 3);
- }
-
- private boolean isRegistered(DialogRunnerI runner, RunResponse action)
- {
- Map