X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2Fdialogrunner%2FDialogRunnerTest.java;h=702601c81f407d780447ceca14ab1f4d630d797f;hb=e9a1c2c372f4bbf6cf658de3dba73ef326b20c20;hp=ec6155165bbc3b7db6d98ea4d434c4542c5151cf;hpb=867c62c23d99dea4681aae74143996679b4c1472;p=jalview.git diff --git a/test/jalview/util/dialogrunner/DialogRunnerTest.java b/test/jalview/util/dialogrunner/DialogRunnerTest.java index ec61551..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 addResponse(RunResponse action) - { - return runner.addResponse(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.addResponse(ok).addResponse(cancel).addResponse(help).addResponse(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); - } }