|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertEquals; |
4 | 4 |
|
5 | | -import java.io.File; |
| 5 | +import java.io.BufferedReader; |
| 6 | +import java.io.IOException; |
| 7 | +import java.io.InputStream; |
| 8 | +import java.io.InputStreamReader; |
6 | 9 | import java.net.URL; |
7 | 10 | import java.nio.charset.StandardCharsets; |
8 | | -import java.nio.file.Files; |
9 | 11 | import java.util.ArrayList; |
10 | 12 | import java.util.Collection; |
11 | 13 | import java.util.List; |
@@ -34,14 +36,24 @@ public ExtensiveEncoderURITest(String uri){ |
34 | 36 | @Parameters |
35 | 37 | public static Collection<String> getMyUris() throws Exception{ |
36 | 38 | URL url = ExtensiveEncoderURITest.class.getResource("/urisForTest.txt"); |
37 | | - String fileName = url.getFile(); |
38 | | - File urisForText = new File(fileName); |
39 | | - |
40 | | - inputs = Files.readAllLines(urisForText.toPath(), StandardCharsets.UTF_8); |
41 | 39 |
|
| 40 | + try( InputStream is = url.openStream() ) { |
| 41 | + InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); |
| 42 | + BufferedReader br = new BufferedReader(isr); |
| 43 | + inputs = readAllLines(br); |
| 44 | + } |
42 | 45 | return inputs; |
43 | 46 | } |
44 | | - |
| 47 | + |
| 48 | + private static List<String> readAllLines(BufferedReader br) throws IOException { |
| 49 | + List<String> lines = new ArrayList<>(); |
| 50 | + String line; |
| 51 | + while ((line = br.readLine()) != null) { |
| 52 | + lines.add(line); |
| 53 | + } |
| 54 | + return lines; |
| 55 | + } |
| 56 | + |
45 | 57 | @Test |
46 | 58 | public void testUrlsFromFile() throws Exception{ |
47 | 59 | assertEquals(this.expected, v.isValidURI("URL", uri, false)); |
|
0 commit comments