This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git

commit f2abb7c091820a3fe1a2c5ca65cf1628809d5cb4
Author: Matthias Bläsing <[email protected]>
AuthorDate: Sat Nov 25 14:38:04 2017 +0100

    Fix SCFTHandlerTest#testUTF8 and reduce duplicate code
    
    From the previous commit the testUTF8 test still failed on windows.
    This change applies the solution from the previous commit (normalization
    of line-endings) also to the testUTF8 case.
---
 .../modules/templates/SCFTHandlerTest.java         | 39 ++++++++--------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git 
a/api.templates/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java
 
b/api.templates/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java
index da750ca..6c559e3 100644
--- 
a/api.templates/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java
+++ 
b/api.templates/test/unit/src/org/netbeans/modules/templates/SCFTHandlerTest.java
@@ -20,13 +20,11 @@
 package org.netbeans.modules.templates;
 
 import java.awt.Dialog;
-import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -223,25 +221,22 @@ public class SCFTHandlerTest extends NbTestCase {
     }
     
     private static String readFile(FileObject fo) throws IOException {
-        byte[] arr = new byte[(int)fo.getSize()];
-        int len = fo.getInputStream().read(arr);
-        assertEquals("Fully read", arr.length, len);
-        String foRead = new 
String(arr).replace(System.getProperty("line.separator"), "\n");
-        return foRead;
+        return readChars(fo, Charset.defaultCharset());
     }
 
     private static String readChars(FileObject fo, Charset set) throws 
IOException {
-        CharBuffer arr = CharBuffer.allocate((int)fo.getSize() * 2);
-        BufferedReader r = new BufferedReader(new 
InputStreamReader(fo.getInputStream(), set));
-        while (r.read(arr) != -1) {
-            // again
+        try (InputStream is = fo.getInputStream()) {
+            StringBuilder sb = new StringBuilder();
+            int read = 0;
+            char[] buffer = new char[1024];
+            InputStreamReader r = new InputStreamReader(is, set);
+            while ((read = r.read(buffer)) > 0) {
+                sb.append(buffer, 0, read);
+            }
+            return sb.toString().replace(System.getProperty("line.separator"), 
"\n");
         }
-        r.close();
-        
-        arr.flip();
-        return arr.toString();
     }
-
+    
      public void testUTF8() throws Exception {
          FileObject root = FileUtil.getConfigRoot();
          FileObject xmldir = FileUtil.createFolder(root, "xml");
@@ -322,15 +317,9 @@ public class SCFTHandlerTest extends NbTestCase {
         if (length <= 0) {
             fail("Too small file: " + length + " for " + snd);
         }
-        InputStream is = snd.getInputStream();
-        InputStreamReader r = new InputStreamReader(is, "UTF-8");
-        char[] cbuf = new char[1024];
-        int len = r.read(cbuf);
-        if (len == -1) {
-            fail("no input stream for " + snd);
-        }
-        String read = new String(cbuf, 0, len);
-        String normRead = read.replace(System.getProperty("line.separator"), 
"\n");
+        
+        String normRead = readChars(snd, Charset.forName("UTF-8"));
+
         txt = txt.replaceAll("print\\('", "").replaceAll("'\\)", "") + "\n";
         
         assertEquals(txt, normRead);

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to