test/java/nio/file/Files/StreamLinesTest.java

Print this page
rev 12681 : 8135091: (fs) java/nio/file/Files/StreamLinesTest.java should test empty files
Summary: In lines() add zero length case and rearrange first loop to avoid duplicate cases.
Reviewed-by: XXX


 121     }
 122 
 123     static Object[] of(String description, IntFunction<String> lineGenerator,
 124                        IntFunction<LineSeparator> separatorGenerator, int n, Charset cs) {
 125         return new Object[]{description, lineGenerator, separatorGenerator, n, cs};
 126     }
 127 
 128     private static final Random random = RandomFactory.getRandom();
 129 
 130     @DataProvider
 131     public static Object[][] lines() {
 132         List<Object[]> l = new ArrayList<>();
 133 
 134         // Include the three supported optimal-line charsets and one
 135         // which does not
 136         List<Charset> charsets = Arrays.asList(StandardCharsets.UTF_8,
 137                                                StandardCharsets.US_ASCII,
 138                                                StandardCharsets.ISO_8859_1,
 139                                                StandardCharsets.UTF_16);
 140         String[] lines = {"", "A", "AB", "ABC", "ABCD"};
 141         int[] linesSizes = {1, 2, 3, 4, 16, 256, 1024};
 142 
 143         for (Charset charset : charsets) {
 144             for (String line : lines) {
 145                 for (int linesSize : linesSizes) {


 146                     for (LineSeparator ls : EnumSet.complementOf(EnumSet.of(LineSeparator.NONE))) {
 147                         String description = String.format("%d lines of \"%s\" with separator %s", linesSize, line, ls);
 148                         l.add(of(description,
 149                                  i -> line,
 150                                  i -> ls,
 151                                  linesSize, charset));
 152                     }
 153                 }






 154             }
 155         }
 156 
 157         for (Charset charset : charsets) {
 158             l.add(of("A maximum of 1024 random lines and separators",
 159                      i -> lines[1 + random.nextInt(lines.length - 1)],
 160                      i -> LineSeparator.values()[random.nextInt(LineSeparator.values().length)],
 161                      1024, charset));
 162         }
 163 
 164         for (Charset charset : charsets) {
 165             l.add(of("One large line with no separators",
 166                      i -> "ABCD",
 167                      i -> LineSeparator.NONE,
 168                      1024, charset));
 169         }
 170 
 171         return l.toArray(new Object[][]{});
 172     }
 173 




 121     }
 122 
 123     static Object[] of(String description, IntFunction<String> lineGenerator,
 124                        IntFunction<LineSeparator> separatorGenerator, int n, Charset cs) {
 125         return new Object[]{description, lineGenerator, separatorGenerator, n, cs};
 126     }
 127 
 128     private static final Random random = RandomFactory.getRandom();
 129 
 130     @DataProvider
 131     public static Object[][] lines() {
 132         List<Object[]> l = new ArrayList<>();
 133 
 134         // Include the three supported optimal-line charsets and one
 135         // which does not
 136         List<Charset> charsets = Arrays.asList(StandardCharsets.UTF_8,
 137                                                StandardCharsets.US_ASCII,
 138                                                StandardCharsets.ISO_8859_1,
 139                                                StandardCharsets.UTF_16);
 140         String[] lines = {"", "A", "AB", "ABC", "ABCD"};
 141         int[] linesSizes = {0, 1, 2, 3, 4, 16, 256, 1024};
 142 
 143         for (Charset charset : charsets) {

 144             for (int linesSize : linesSizes) {
 145                 if (linesSize > 0) {
 146                     for (String line : lines) {
 147                         for (LineSeparator ls : EnumSet.complementOf(EnumSet.of(LineSeparator.NONE))) {
 148                             String description = String.format("%d lines of \"%s\" with separator %s", linesSize, line, ls);
 149                             l.add(of(description,
 150                                     i -> line,
 151                                     i -> ls,
 152                                     linesSize, charset));
 153                         }
 154                     }
 155                 } else {
 156                     l.add(of("Empty file: 0 lines",
 157                             i -> "",
 158                             i -> LineSeparator.NONE,
 159                             0, charset));
 160                 }
 161             }
 162         }
 163 
 164         for (Charset charset : charsets) {
 165             l.add(of("A maximum of 1024 random lines and separators",
 166                      i -> lines[1 + random.nextInt(lines.length - 1)],
 167                      i -> LineSeparator.values()[random.nextInt(LineSeparator.values().length)],
 168                      1024, charset));
 169         }
 170 
 171         for (Charset charset : charsets) {
 172             l.add(of("One large line with no separators",
 173                      i -> "ABCD",
 174                      i -> LineSeparator.NONE,
 175                      1024, charset));
 176         }
 177 
 178         return l.toArray(new Object[][]{});
 179     }
 180