From 6723fff70de0a8576fab9196e99ece7ae67f3dbf Mon Sep 17 00:00:00 2001 From: James Procter Date: Fri, 7 Jul 2023 14:58:52 +0100 Subject: [PATCH] JAL-4195 add exception handling for all other CommandsTest tests and remove errant class-level @Test tag --- test/jalview/bin/CommandsTest.java | 124 ++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 61892df..81f0e1f 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -19,7 +19,6 @@ import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.util.ArrayUtils; -@Test public class CommandsTest { private static final String testfiles = "test/jalview/bin/argparser/testfiles"; @@ -77,39 +76,49 @@ public class CommandsTest public void commandsOpenTest(String cmdLine, boolean cmdArgs, int numFrames, String[] sequences) { - String[] args = (cmdLine + " --gui").split("\\s+"); - callJalviewMain(args); - Commands cmds = Jalview.getInstance().getCommands(); - Assert.assertNotNull(cmds); - Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs, - "Commands were not provided in the args"); - Assert.assertEquals(cmds.argsWereParsed(), cmdArgs, - "Overall command parse and operation is false"); + try + { + String[] args = (cmdLine + " --gui").split("\\s+"); + callJalviewMain(args); + Commands cmds = Jalview.getInstance().getCommands(); + Assert.assertNotNull(cmds); + Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs, + "Commands were not provided in the args"); + Assert.assertEquals(cmds.argsWereParsed(), cmdArgs, + "Overall command parse and operation is false"); - Assert.assertEquals(Desktop.getAlignFrames().length, numFrames, - "Wrong number of AlignFrames"); + Assert.assertEquals(Desktop.getAlignFrames().length, numFrames, + "Wrong number of AlignFrames"); - if (sequences != null) - { - Set openedSequenceNames = new HashSet<>(); - AlignFrame[] afs = Desktop.getAlignFrames(); - for (AlignFrame af : afs) + if (sequences != null) { - openedSequenceNames - .addAll(af.getViewport().getAlignment().getSequenceNames()); - } - for (String sequence : sequences) - { - Assert.assertTrue(openedSequenceNames.contains(sequence), - "Sequence '" + sequence - + "' was not found in opened alignment files: " - + cmdLine + ".\nOpened sequence names are:\n" - + String.join("\n", openedSequenceNames)); + Set openedSequenceNames = new HashSet<>(); + AlignFrame[] afs = Desktop.getAlignFrames(); + for (AlignFrame af : afs) + { + openedSequenceNames.addAll( + af.getViewport().getAlignment().getSequenceNames()); + } + for (String sequence : sequences) + { + Assert.assertTrue(openedSequenceNames.contains(sequence), + "Sequence '" + sequence + + "' was not found in opened alignment files: " + + cmdLine + ".\nOpened sequence names are:\n" + + String.join("\n", openedSequenceNames)); + } } - } - Assert.assertFalse( - lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST")); + Assert.assertFalse( + lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST")); + } catch (Exception x) + { + Assert.fail("Unexpected exception during commandsOpenTest", x); + } finally + { + tearDown(); + + } } @Test(groups = "Functional", dataProvider = "structureImageOutputFiles") @@ -118,26 +127,35 @@ public class CommandsTest { cleanupFiles(filenames); String[] args = (cmdLine + " --gui").split("\\s+"); - callJalviewMain(args); - Commands cmds = Jalview.getInstance().getCommands(); - Assert.assertNotNull(cmds); - File lastFile = null; - for (String filename : filenames) + try { - File file = new File(filename); - Assert.assertTrue(file.exists(), "File '" + filename - + "' was not created by '" + cmdLine + "'"); - Assert.assertTrue(file.isFile(), "File '" + filename - + "' is not a file from '" + cmdLine + "'"); - Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename - + "' has no content from '" + cmdLine + "'"); - // make sure the successive output files get bigger! - if (lastFile != null) - Assert.assertTrue( - Files.size(file.toPath()) > Files.size(lastFile.toPath())); + callJalviewMain(args); + Commands cmds = Jalview.getInstance().getCommands(); + Assert.assertNotNull(cmds); + File lastFile = null; + for (String filename : filenames) + { + File file = new File(filename); + Assert.assertTrue(file.exists(), "File '" + filename + + "' was not created by '" + cmdLine + "'"); + Assert.assertTrue(file.isFile(), "File '" + filename + + "' is not a file from '" + cmdLine + "'"); + Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename + + "' has no content from '" + cmdLine + "'"); + // make sure the successive output files get bigger! + if (lastFile != null) + Assert.assertTrue(Files.size(file.toPath()) > Files + .size(lastFile.toPath())); + } + } catch (Exception x) + { + Assert.fail("Unexpected exception during structureImageOutputTest", + x); + } finally + { + cleanupFiles(filenames); + tearDown(); } - cleanupFiles(filenames); - tearDown(); } @Test(groups = "Functional", dataProvider = "argfileOutputFiles") @@ -146,6 +164,7 @@ public class CommandsTest { cleanupFiles(filenames); String[] args = (cmdLine + " --gui").split("\\s+"); + try { callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); @@ -164,8 +183,15 @@ public class CommandsTest Assert.assertTrue( Files.size(file.toPath()) > Files.size(lastFile.toPath())); } - cleanupFiles(filenames); - tearDown(); + } catch (Exception x) + { + Assert.fail("Unexpected exception during argFilesGlobAndSubstitutions", + x); + } finally + { + cleanupFiles(filenames); + tearDown(); + } } @DataProvider(name = "structureImageOutputFiles") -- 1.7.10.2