package net.sourceforge.htmlunit.cyberneko.filters;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import junit.framework.TestCase;

import org.apache.xerces.xni.parser.XMLDocumentFilter;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
import net.sourceforge.htmlunit.cyberneko.HTMLConfiguration;

/**
 * Unit tests for {@link Writer}.
 *
 * @author Marc Guillemot
 */
public class WriterTest extends TestCase {

    /**
     * Regression test for bug: writer changed attribute value causing NPE in 2nd writer.
     * http://sourceforge.net/support/tracker.php?aid=2815779
     */
    public void testEmptyAttribute() throws Exception {
        
        final String content = "<html><head>"
            + "<meta name='COPYRIGHT' content='SOMEONE' />"
            + "</head><body></body></html>";
        final InputStream inputStream = new ByteArrayInputStream(content.getBytes()); 
        
        final XMLDocumentFilter[] filters = {
            new net.sourceforge.htmlunit.cyberneko.Writer(new ByteArrayOutputStream(), "UTF-8"),
            new net.sourceforge.htmlunit.cyberneko.Writer(new ByteArrayOutputStream(), "UTF-8")
        };
        
        // create HTML parser
        final XMLParserConfiguration parser = new HTMLConfiguration();
        parser.setProperty("http://cyberneko.org/html/properties/filters", filters);

        XMLInputSource source = new XMLInputSource(null, "currentUrl", null, inputStream, "UTF-8");
        
        parser.parse(source);
        inputStream.close();
    }
}

@@ -912,24 +912,25 @@
 html%3E%22;%0A
+%0A
         
 final In
@@ -921,22 +921,21 @@
         
-final 
+try (
 InputStr
@@ -996,17 +996,19 @@
 Bytes())
-;
+) %7B
  %0A      
@@ -1001,37 +1001,32 @@
 ())) %7B %0A        
-%0A    
     final XMLDoc
@@ -1055,32 +1055,36 @@
 = %7B%0A            
+ 
+   
 new net.sourcefo
@@ -1152,16 +1152,20 @@
 TF-8%22),%0A
+    
         
@@ -1264,20 +1264,20 @@
     
-%7D;%0A
     
+%7D;%0A%0A
     
-%0A
     
@@ -1302,16 +1302,20 @@
  parser%0A
+    
         
@@ -1381,24 +1381,28 @@
 ();%0A        
+    
 parser.setPr
@@ -1466,25 +1466,31 @@
 lters);%0A
-%0A
+    %0A  
         
 XMLInput
@@ -1481,16 +1481,18 @@
         
+  
 XMLInput
@@ -1575,25 +1575,21 @@
 TF-8%22);%0A
-    
+%0A
     
-%0A
         
@@ -1622,28 +1622,9 @@
     
-inputStream.close();
+%7D
 %0A   

use try with resource