JAL-4420 Tests for new FileUtils methods
authorBen Soares <b.soares@dundee.ac.uk>
Fri, 17 May 2024 14:56:11 +0000 (15:56 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Fri, 17 May 2024 14:56:11 +0000 (15:56 +0100)
test/jalview/util/FileUtilsTest.java

index 666b33b..3cc9ca6 100644 (file)
@@ -157,4 +157,54 @@ public class FileUtilsTest
     };
   }
 
+  @Test(
+    groups = "Functional",
+    dataProvider = "stringFilenamesBaseAndExtensionsData")
+  public void stringGetBaseAndExtensionTest(String filename,
+          String extension, String base)
+  {
+    String thisBase = FileUtils.getBase(filename);
+    Assert.assertEquals(thisBase, base,
+            "base part of path and filename not as expected");
+    String thisExtension = FileUtils.getExtension(filename);
+    Assert.assertEquals(thisExtension, extension,
+            "extension part of filename not as expected");
+  }
+
+  @DataProvider(name = "stringFilenamesBaseAndExtensionsData")
+  public Object[][] stringFilenamesBaseAndExtensionsData()
+  {
+    return new Object[][] {
+        /*
+         * String full URL or path
+         * String base the above but without the extension if there is one
+         * String extension the filename extension if there is one
+         */
+        /*
+        */
+        { "/examples/uniref50.fa", "fa", "/examples/uniref50." },
+        { "/examples/uniref50", null, "/examples/uniref50" },
+        { "/examples/.uniref50", null, "/examples/.uniref50" },
+        { "/exampl.es/uniref50", null, "/exampl.es/uniref50" },
+        { "/examples/uniref50.", "", "/examples/uniref50." },
+        { "examples/uniref50.fa", "fa", "examples/uniref50." },
+        { "examples/uniref50", null, "examples/uniref50" },
+        { "examples/.uniref50", null, "examples/.uniref50" },
+        { "exampl.es/uniref50", null, "exampl.es/uniref50" },
+        { "examples/uniref50.", "", "examples/uniref50." },
+        { "https://www.jalview.org:443/examples/uniref50.fa", "fa",
+            "https://www.jalview.org:443/examples/uniref50." },
+        { "https://www.jalview.org:443/examples/uniref50", null,
+            "https://www.jalview.org:443/examples/uniref50" },
+        { "https://www.jalview.org:443/examples/.uniref50", null,
+            "https://www.jalview.org:443/examples/.uniref50" },
+        { "https://www.jalview.org:443/exampl.es/uniref50", null,
+            "https://www.jalview.org:443/exampl.es/uniref50" },
+        { "https://www.jalview.org:443/examples/uniref50.", "",
+            "https://www.jalview.org:443/examples/uniref50." },
+        /*
+        */
+        //
+    };
+  }
 }