JAL-4277 fixed and improved tests
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 7 Sep 2023 22:28:24 +0000 (23:28 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 7 Sep 2023 22:28:24 +0000 (23:28 +0100)
test/jalview/util/FileUtilsTest.java

index e977efa..1597718 100644 (file)
@@ -56,29 +56,26 @@ public class FileUtilsTest
   }
 
   @Test(groups = "Functional", dataProvider = "dirnamesAndBasenames")
-  public void testDirnamesAndBasenames(String filename, int where,
-          String dirname, String basename, String notInDirname)
+  public void testDirnamesAndBasenames(String filename, String dirname,
+          String endsWith, String basename, String notInDirname)
   {
     File file = new File(filename);
     String d = FileUtils.getDirname(file);
     String b = FileUtils.getBasename(file);
     Assert.assertEquals(b, basename);
-    if (where == 0)
-      Assert.assertEquals(d, dirname);
-    else if (where < 0)
-      Assert.assertTrue(d.startsWith(dirname),
-              "getDirname(" + file.getPath() + ")=" + d
-                      + " didn't start with '" + dirname + "'");
-    else if (where > 0)
-      Assert.assertTrue(d.endsWith(dirname), "getDirname(" + file.getPath()
-              + ")=" + d + " didn't end with '" + d + "'");
+    Assert.assertTrue(d.startsWith(dirname), "getDirname(" + file.getPath()
+            + ")=" + d + " didn't start with '" + dirname + "'");
+    Assert.assertTrue(d.endsWith(endsWith), "getDirname(" + file.getPath()
+            + ")=" + d + " didn't end with '" + endsWith + "'");
 
     // ensure dirname doesn't end with basename (which means you can't use same
     // filename as dir in tests!)
-    Assert.assertFalse(d.endsWith(b));
+    Assert.assertFalse(d.endsWith(b), "Processed dirname '" + d
+            + "' ends with '" + b + "' when it shouldn't");
 
     if (notInDirname != null)
-      Assert.assertFalse(d.contains(notInDirname));
+      Assert.assertFalse(d.contains(notInDirname), "Processed directory '"
+              + d + "' contains '" + notInDirname + "' when it shouldn't");
   }
 
   @DataProvider(name = "patternsAndMinNumFiles")
@@ -112,11 +109,12 @@ public class FileUtilsTest
       e.printStackTrace();
     }
     return new Object[][] { // -1=startsWith, 0=equals, 1=endsWith
-        { "~/hello/sailor", -1, homeDir, "sailor", "~" }, //
-        { "~/hello/sailor", 1, "/hello", "sailor", "~" }, //
-        { "./examples/uniref50.fa", -1, "/", "uniref50", "." }, //
-        { "./examples/uniref50.fa", 1, "/examples", "uniref50", "." }, //
-        { "examples/uniref50.fa", 1, "/examples", "uniref50", ".fa" }, //
+        { "~/hello/sailor", homeDir, "/hello", "sailor", "~" }, //
+        { "./examples/uniref50.fa", "./", "examples", "uniref50", "Users" }, //
+        { "./examples/uniref50.1.fa", "./", "examples", "uniref50.1",
+            "Users" }, //
+        { "examples/uniref50.fa", "examples", "examples", "uniref50",
+            ".fa" }, //
     };
   }