JAL-4121 slight refactoring of method name and added tests for headless assumptions...
[jalview.git] / test / jalview / bin / argparser / ArgParserTest.java
index ca63e44..461738b 100644 (file)
@@ -90,7 +90,7 @@ public class ArgParserTest
     Assert.assertTrue(b.contains(a));
     if (a == Arg.PROPS)
     {
-      Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
+      Properties bP = Cache.bootstrapProperties(b.getValue(Arg.PROPS));
       Assert.assertNotNull(bP);
       Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST)));
       Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST));
@@ -130,7 +130,7 @@ public class ArgParserTest
     Assert.assertFalse(b.contains(Arg.APPEND));
     if (a == Arg.PROPS)
     {
-      Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS));
+      Properties bP = Cache.bootstrapProperties(b.getValue(Arg.PROPS));
       Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST)));
     }
   }
@@ -340,4 +340,78 @@ public class ArgParserTest
         //
     };
   }
+
+  @Test(groups = "Functional", dataProvider = "bootstrapArgsData")
+  public void bootstrapArgsValuesTest(String commandLineArgs, Arg a,
+          String valS, boolean valB, boolean headlessValue)
+  {
+    String[] args = commandLineArgs.split("\\s+");
+    BootstrapArgs bsa = BootstrapArgs.getBootstrapArgs(args);
+    if (a != null)
+    {
+      if (valS != null)
+      {
+        Assert.assertEquals(bsa.getValue(a), valS,
+                "BootstrapArg " + a.argString()
+                        + " value does not match expected '" + valS + "'");
+      }
+      else
+      {
+        Assert.assertEquals(bsa.getBoolean(a), valB,
+                "Boolean/Unary value of BootstrapArg " + a.argString()
+                        + "' is not the expected '" + valB + "'");
+      }
+    }
+
+    boolean isHeadless = bsa.isHeadless();
+    Assert.assertEquals(isHeadless, headlessValue,
+            "Assumed headless setting '" + isHeadless + "' is wrong.");
+  }
+
+  @DataProvider(name = "bootstrapArgsData")
+  public Object[][] bootstrapArgsData()
+  {
+    return new Object[][] {
+        /*
+         * cmdline args
+         * Arg (null if only testing headless)
+         * String value if there is one (null otherwise)
+         * boolean value if String value is null
+         * expected value of isHeadless()
+         */
+        /*
+        */
+        { "--open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/",
+            Arg.JABAWS, "https://forwardsandbackwards.com/", false, true },
+        { "--help-all --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/",
+            Arg.HELP, null, true, true },
+        { "--help-all --nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/",
+            Arg.NEWS, null, false, true },
+        { "--help --nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/",
+            Arg.NEWS, null, false, true },
+        { "--help-opening --nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/",
+            Arg.NEWS, null, false, true },
+        { "--nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/",
+            Arg.NEWS, null, false, true },
+        { "--open thisway.fa --image thatway.png", null, null, false,
+            true },
+        { "--open thisway.fa --output thatway.png", null, null, false,
+            true },
+        { "--open thisway.fa --image thatway.png --noheadless", null, null,
+            false, false },
+        { "--open thisway.fa --output thatway.png --noheadless", null, null,
+            false, false },
+        { "--open thisway.fa --image thatway.png --gui", null, null, false,
+            false },
+        { "--open thisway.fa --output thatway.png --gui", null, null, false,
+            false },
+        // --gui takes precedence
+        { "--open thisway.fa --image thatway.png --gui --headless", null,
+            null, false, false },
+        { "--open thisway.fa --output thatway.png --gui --headless", null,
+            null, false, false },
+        //
+    };
+  }
+
 }