|
31 | 31 | package org.scijava.java3d; |
32 | 32 |
|
33 | 33 | import static org.junit.Assert.assertEquals; |
| 34 | +import static org.junit.Assert.assertTrue; |
34 | 35 |
|
35 | 36 | import java.io.File; |
36 | 37 | import java.io.IOException; |
37 | 38 | import java.util.HashSet; |
| 39 | +import java.util.Set; |
| 40 | +import java.util.stream.Collectors; |
38 | 41 |
|
39 | 42 | import org.junit.After; |
40 | 43 | import org.junit.Before; |
@@ -65,60 +68,70 @@ public void setUp() throws IOException { |
65 | 68 |
|
66 | 69 | @After |
67 | 70 | public void tearDown() { |
| 71 | + context.dispose(); |
68 | 72 | FileUtils.deleteRecursively(tmp1); |
69 | 73 | FileUtils.deleteRecursively(tmp2); |
70 | 74 | } |
71 | 75 |
|
72 | 76 | @Test |
73 | 77 | public void testGetLibExtLocations() throws IOException { |
74 | | - final HashSet<File> expected = new HashSet<File>(); |
| 78 | + final HashSet<String> expected = new HashSet<>(); |
75 | 79 |
|
76 | 80 | System.setProperty("java.ext.dirs", tmp1.getAbsolutePath() + ":" + |
77 | 81 | tmp2.getAbsolutePath()); |
78 | 82 |
|
79 | | - final File j3dcore1 = createFile(tmp1, "j3dcore.jar"); |
| 83 | + final String j3dcore1 = createFile(tmp1, "j3dcore.jar"); |
80 | 84 | expected.add(j3dcore1); |
81 | | - assertEquals(expected, libExtFiles()); |
| 85 | + assertEquals(expected, libExtPaths()); |
82 | 86 |
|
83 | | - final File j3dcore2 = createFile(tmp2, "j3dcore.jar"); |
| 87 | + final String j3dcore2 = createFile(tmp2, "j3dcore.jar"); |
84 | 88 | expected.add(j3dcore2); |
85 | | - assertEquals(expected, libExtFiles()); |
| 89 | + assertEquals(expected, libExtPaths()); |
86 | 90 |
|
87 | | - final File j3dutils = createFile(tmp2, "j3dutils.jar"); |
| 91 | + final String j3dutils = createFile(tmp2, "j3dutils.jar"); |
88 | 92 | expected.add(j3dutils); |
89 | | - final File jogl = createFile(tmp1, "jogl-2.2.0.jar"); |
| 93 | + final String jogl = createFile(tmp1, "jogl-2.2.0.jar"); |
90 | 94 | expected.add(jogl); |
91 | | - assertEquals(expected, libExtFiles()); |
| 95 | + assertEquals(expected, libExtPaths()); |
92 | 96 |
|
93 | | - final File vecmath = createFile(tmp1, "vecmath.jar"); |
| 97 | + final String vecmath = createFile(tmp1, "vecmath.jar"); |
94 | 98 | createFile(tmp2, "red-herring"); |
95 | 99 | expected.add(vecmath); |
96 | | - assertEquals(expected, libExtFiles()); |
| 100 | + assertEquals(expected, libExtPaths()); |
97 | 101 |
|
98 | 102 | System.setProperty("java.ext.dirs", tmp1.getAbsolutePath()); |
99 | 103 | expected.remove(j3dcore2); |
100 | 104 | expected.remove(j3dutils); |
101 | | - assertEquals(expected, libExtFiles()); |
| 105 | + assertEquals(expected, libExtPaths()); |
102 | 106 |
|
103 | 107 | System.setProperty("java.ext.dirs", ""); |
104 | 108 | expected.clear(); |
105 | | - assertEquals(expected, libExtFiles()); |
| 109 | + assertEquals(expected, libExtPaths()); |
106 | 110 |
|
107 | 111 | System.clearProperty("java.ext.dirs"); |
108 | | - assertEquals(expected, libExtFiles()); |
| 112 | + assertEquals(expected, libExtPaths()); |
109 | 113 | } |
110 | 114 |
|
111 | 115 | // -- Helper methods -- |
112 | 116 |
|
113 | | - private File createFile(final File dir, final String name) throws IOException |
| 117 | + private String createFile(final File dir, final String name) throws IOException |
114 | 118 | { |
115 | 119 | final File file = new File(dir, name); |
116 | | - file.createNewFile(); |
117 | | - return file; |
| 120 | + assertTrue(file.createNewFile()); |
| 121 | + return truePath(file); |
118 | 122 | } |
119 | 123 |
|
120 | | - private HashSet<File> libExtFiles() { |
121 | | - return new HashSet<File>(j3d.getLibExtLocations()); |
| 124 | + private Set<String> libExtPaths() { |
| 125 | + return j3d.getLibExtLocations().stream() |
| 126 | + .map(f -> truePath(f)) |
| 127 | + .collect(Collectors.toSet()); |
122 | 128 | } |
123 | 129 |
|
| 130 | + private static String truePath(File f) { |
| 131 | + try { |
| 132 | + return f.getCanonicalPath(); |
| 133 | + } catch (IOException e) { |
| 134 | + throw new RuntimeException(e); |
| 135 | + } |
| 136 | + } |
124 | 137 | } |
0 commit comments