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

@@ -136,23 +136,30 @@
         List<Charset> charsets = Arrays.asList(StandardCharsets.UTF_8,
                                                StandardCharsets.US_ASCII,
                                                StandardCharsets.ISO_8859_1,
                                                StandardCharsets.UTF_16);
         String[] lines = {"", "A", "AB", "ABC", "ABCD"};
-        int[] linesSizes = {1, 2, 3, 4, 16, 256, 1024};
+        int[] linesSizes = {0, 1, 2, 3, 4, 16, 256, 1024};
 
         for (Charset charset : charsets) {
-            for (String line : lines) {
                 for (int linesSize : linesSizes) {
+                if (linesSize > 0) {
+                    for (String line : lines) {
                     for (LineSeparator ls : EnumSet.complementOf(EnumSet.of(LineSeparator.NONE))) {
                         String description = String.format("%d lines of \"%s\" with separator %s", linesSize, line, ls);
                         l.add(of(description,
                                  i -> line,
                                  i -> ls,
                                  linesSize, charset));
                     }
                 }
+                } else {
+                    l.add(of("Empty file: 0 lines",
+                            i -> "",
+                            i -> LineSeparator.NONE,
+                            0, charset));
+                }
             }
         }
 
         for (Charset charset : charsets) {
             l.add(of("A maximum of 1024 random lines and separators",