JAL-2994 utility method to match a list of folder/file patterns
[jalview.git] / test / jalview / util / FileUtilsTest.java
index aed9142..07fd375 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.util;
 
+import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
 import java.io.IOException;
@@ -13,7 +14,7 @@ public class FileUtilsTest
   @Test(groups = "Functional")
   public void testFindMatchingPaths() throws IOException
   {
-    String expect1 = Paths.get("../jalview/examples/plantfdx.fa")
+    String expect1 = Paths.get("..", "jalview", "examples", "plantfdx.fa")
             .toString();
     String expect2 = Paths.get("../jalview/examples/plantfdx.features")
             .toString();
@@ -21,10 +22,52 @@ public class FileUtilsTest
             .get("../jalview/examples/testdata/plantfdx.features")
             .toString();
 
-    List<String> matches = FileUtils.findMatchingPaths(".*/plant.*\\.f.*",
-            Paths.get(".."));
+    List<String> matches = FileUtils
+            .findMatchingPaths(Paths.get(".."),
+            ".*[/\\\\]plant.*\\.f.*");
+    System.out.println(matches);
     assertTrue(matches.contains(expect1));
     assertTrue(matches.contains(expect2));
     assertTrue(matches.contains(expect3));
   }
+
+  @Test(groups = "External")
+  public void testWindowsPath() throws IOException
+  {
+    if (System.getProperty("os.name").startsWith("Windows"))
+    {
+      /*
+       * should pass provided Eclipse is installed
+       */
+      List<String> matches = FileUtils.findMatches("C:\\",
+              "Program Files*/eclips*/eclips?.exe");
+      assertFalse(matches.isEmpty());
+
+      /*
+       * should pass provided Chimera is installed
+       */
+      matches = FileUtils.findMatches("C:\\",
+              "Program Files*/Chimera*/bin/{chimera,chimera.exe}");
+      assertFalse(matches.isEmpty());
+    }
+  }
+
+  @Test(groups = "Functional")
+  public void testFindMatches() throws IOException
+  {
+    String expect1 = Paths.get("..", "jalview", "examples", "plantfdx.fa")
+            .toString();
+    String expect2 = Paths.get("../jalview/examples/plantfdx.features")
+            .toString();
+    String expect3 = Paths
+            .get("../jalview/examples/testdata/plantfdx.features")
+            .toString();
+  
+    List<String> matches = FileUtils
+            .findMatches("..", "jalview/ex*/plant*.f*");
+    System.out.println(matches);
+    assertTrue(matches.contains(expect1));
+    assertTrue(matches.contains(expect2));
+    assertFalse(matches.contains(expect3));
+  }
 }