JAL-629 Commands more objecty, less classy. FileLoader with sync option (or rather...
[jalview.git] / test / jalview / bin / CommandsTest.java
index 9c763e1..65162f3 100644 (file)
@@ -3,6 +3,7 @@ package jalview.bin;
 import java.util.Date;
 
 import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -30,34 +31,49 @@ public class CommandsTest
     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
   }
 
+  @AfterMethod(alwaysRun = true)
+  public void tearDown()
+  {
+    Desktop.instance.closeAll_actionPerformed(null);
+  }
+
   @Test(groups = "Functional", dataProvider = "cmdLines")
   public void commandsOpenTest(String cmdLine, String sequence)
   {
     String[] args = cmdLine.split("\\s+");
     Jalview.main(args);
-    ArgParser argparser = new ArgParser(args);
-    boolean commandsSuccess = Commands.processArgs(argparser, false);
-    Assert.assertTrue(commandsSuccess, "Overall commandsSuccess is false");
+    Commands cmds = Jalview.getInstance().getCommands();
+    Assert.assertNotNull(cmds);
+    Assert.assertTrue(cmds.commandArgsProvided(),
+            "Commands were not provided in the args");
+    Assert.assertTrue(cmds.argsWereParsed(),
+            "Overall command parse and operation is false");
 
     if (sequence != null)
     {
-      AlignFrame[] afs = Desktop.getAlignFrames();
-      boolean found = false;
-      ALIGNFRAME: for (AlignFrame af : afs)
+      Assert.assertTrue(lookForSequenceName(sequence),
+              "Sequence '" + sequence
+                      + "' was not found in opened alignment files: "
+                      + cmdLine);
+    }
+
+    System.out.println("##### GOT TO END");
+  }
+
+  public static boolean lookForSequenceName(String sequenceName)
+  {
+    AlignFrame[] afs = Desktop.getAlignFrames();
+    for (AlignFrame af : afs)
+    {
+      for (String name : af.getViewport().getAlignment().getSequenceNames())
       {
-        for (String name : af.getViewport().getAlignment()
-                .getSequenceNames())
+        if (sequenceName.equals(name))
         {
-          if (sequence.equals(name))
-          {
-            found = true;
-            break ALIGNFRAME;
-          }
+          return true;
         }
       }
-      Assert.assertTrue(found, "Sequence '" + sequence
-              + "' was not found in opened alignment files: " + cmdLine);
     }
+    return false;
   }
 
   @DataProvider(name = "cmdLines")