changeset 12685:4226ee94c70d

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: rriggs
author bpb
date Fri, 04 Sep 2015 14:16:34 -0700
parents ca461a33aa8b
children 9a1abc6aada3
files test/java/nio/file/Files/StreamLinesTest.java
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/nio/file/Files/StreamLinesTest.java	Fri Sep 04 19:55:40 2015 +0000
+++ b/test/java/nio/file/Files/StreamLinesTest.java	Fri Sep 04 14:16:34 2015 -0700
@@ -138,18 +138,25 @@
                                                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) {
-                    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));
+            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));
                 }
             }
         }