JAL-2994 put ‘\’ first in character class clause of regex - otherwise doesn’t compile...
[jalview.git] / test / jalview / util / FileUtilsTest.java
1 package jalview.util;
2
3 import static org.testng.Assert.assertFalse;
4 import static org.testng.Assert.assertTrue;
5
6 import java.io.IOException;
7 import java.nio.file.Paths;
8 import java.util.List;
9
10 import org.testng.annotations.Test;
11
12 public class FileUtilsTest
13 {
14   @Test(groups = "Functional")
15   public void testFindMatchingPaths() throws IOException
16   {
17     String expect1 = Paths.get("..", "jalview", "examples", "plantfdx.fa")
18             .toString();
19     String expect2 = Paths.get("../jalview/examples/plantfdx.features")
20             .toString();
21     String expect3 = Paths
22             .get("../jalview/examples/testdata/plantfdx.features")
23             .toString();
24
25     List<String> matches = FileUtils
26             .findMatchingPaths(Paths.get(".."),
27                     ".*[\\\\/]plant.*\\.f.*");
28     System.out.println(matches);
29     assertTrue(matches.contains(expect1));
30     assertTrue(matches.contains(expect2));
31     assertTrue(matches.contains(expect3));
32   }
33
34   @Test(groups = "External")
35   public void testWindowsPath() throws IOException
36   {
37     if (System.getProperty("os.name").startsWith("Windows"))
38     {
39       /*
40        * should pass provided Eclipse is installed
41        */
42       List<String> matches = FileUtils.findMatches("C:\\",
43               "Program Files*/eclips*/eclips?.exe");
44       assertFalse(matches.isEmpty());
45
46       /*
47        * should pass provided Chimera is installed
48        */
49       matches = FileUtils.findMatches("C:\\",
50               "Program Files*/Chimera*/bin/{chimera,chimera.exe}");
51       assertFalse(matches.isEmpty());
52     }
53   }
54
55   @Test(groups = "Functional")
56   public void testFindMatches() throws IOException
57   {
58     String expect1 = Paths.get("..", "jalview", "examples", "plantfdx.fa")
59             .toString();
60     String expect2 = Paths.get("../jalview/examples/plantfdx.features")
61             .toString();
62     String expect3 = Paths
63             .get("../jalview/examples/testdata/plantfdx.features")
64             .toString();
65   
66     List<String> matches = FileUtils
67             .findMatches("..", "jalview/ex*/plant*.f*");
68     System.out.println(matches);
69     assertTrue(matches.contains(expect1));
70     assertTrue(matches.contains(expect2));
71     assertFalse(matches.contains(expect3));
72   }
73 }