/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 */

package org.apache.jmeter.util;

import static org.junit.Assert.*;

import java.io.PrintStream;

import org.hamcrest.CoreMatchers;
import org.junit.Test;

public class XPathUtilTest {

    @Test
    public void testFormatXmlSimple() {
        assertThat(XPathUtil.formatXml("<one foo='bar'>Test</one>"),
                CoreMatchers.is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                        + "<one foo=\"bar\">Test</one>\n"));
    }

    @Test
    public void testFormatXmlComplex() {
        assertThat(
                XPathUtil.formatXml(
                        "<one foo='bar'><two/><three><four p=\"1\"/></three>...</one>"),
                CoreMatchers.is("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                        + "<one foo=\"bar\">\n" + "  <two/>\n" + "  <three>\n"
                        + "    <four p=\"1\"/>\n" + "  </three>" + "..."
                        + "</one>\n"));
    }

    @Test()
    public void testFormatXmlInvalid() {
        PrintStream origErr = System.err;
        // The parser will print an error, so let it go somewhere, where we will
        // not see it
        System.setErr(null);
        assertThat("No well formed xml here", CoreMatchers
                .is(XPathUtil.formatXml("No well formed xml here")));
        System.setErr(origErr);
    }
}

@@ -980,16 +980,88 @@
 Test %7B%0A%0A
+    final String lineSeparator = System.getProperty(%22line.separator%22);%0A%0A
     @Tes
@@ -1054,32 +1054,32 @@
 r%22);%0A%0A    @Test%0A
-
     public void 
@@ -1298,27 +1298,41 @@
 %22%3ETest%3C/one%3E
-%5Cn%22
+%22 + lineSeparator
 ));%0A    %7D%0A%0A 
@@ -1551,32 +1551,59 @@
 CoreMatchers.is(
+String.join(lineSeparator, 
 %22%3C?xml version=%5C
@@ -1621,33 +1621,51 @@
 ding=%5C%22UTF-8%5C%22?%3E
-%22
+%3Cone foo=%5C%22bar%5C%22%3E%22,
 %0A               
@@ -1677,48 +1677,43 @@
     
-+ %22%3Cone foo=%5C%22bar%5C%22%3E%5Cn%22 + %22  %3Ctwo/%3E%5Cn%22 +
+%22  %3Ctwo/%3E%22,%0A                       
  %22  
@@ -1719,19 +1719,18 @@
  %3Cthree%3E
-%5Cn
 %22
+,
 %0A       
@@ -1745,18 +1745,16 @@
         
- +
  %22    %3Cf
@@ -1770,13 +1770,34 @@
 %5C%22/%3E
-%5Cn%22 +
+%22,%0A                       
  %22  
@@ -1808,17 +1808,19 @@
 ree%3E
-%22 + %22...%22
+...%3C/one%3E%22,
 %0A   
@@ -1844,20 +1844,11 @@
     
-+ %22%3C/one%3E%5Cn%22
+%22%22)
 ));%0A

Use a OS dependent lineseparator to compare the results of the XPath-util.