BAEL-952 Removed mutable state by having separate files for tests (#1994)

This commit is contained in:
Nikhil Khatwani 2017-06-05 21:32:27 +05:30 committed by Predrag Maric
parent ecc91a6108
commit 97c1291359
17 changed files with 177 additions and 26 deletions

4
xml/src/main/java/com/baeldung/xml/Dom4JParser.java Normal file → Executable file
View File

@ -82,7 +82,7 @@ public class Dom4JParser {
title.setText(title.getText() + " updated");
}
}
XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_updated.xml")));
XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_dom4j_updated.xml")));
writer.write(document);
writer.close();
} catch (DocumentException e) {
@ -110,7 +110,7 @@ public class Dom4JParser {
tutorialElement.addElement("author").addText("Dom4J tech writer");
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_new.xml")), format);
XMLWriter writer = new XMLWriter(new FileWriter(new File("src/test/resources/example_dom4j_new.xml")), format);
writer.write(document);
writer.close();
} catch (IOException e) {

View File

@ -1,6 +1,8 @@
package com.baeldung.xml;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@ -10,9 +12,9 @@ import org.w3c.dom.NodeList;
public class DefaultParserUnitTest {
final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_default_parser.xml";
final String fileNameSpace = "src/test/resources/example_namespace.xml";
final String fileNameSpace = "src/test/resources/example_default_parser_namespace.xml";
DefaultParser parser;

View File

@ -13,7 +13,7 @@ import org.junit.Test;
public class Dom4JParserUnitTest {
final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_dom4j.xml";
Dom4JParser parser;
@ -61,7 +61,7 @@ public class Dom4JParserUnitTest {
parser = new Dom4JParser(new File(fileName));
parser.generateModifiedDocument();
File generatedFile = new File("src/test/resources/example_updated.xml");
File generatedFile = new File("src/test/resources/example_dom4j_updated.xml");
assertTrue(generatedFile.exists());
parser.setFile(generatedFile);
@ -76,13 +76,12 @@ public class Dom4JParserUnitTest {
parser = new Dom4JParser(new File(fileName));
parser.generateNewDocument();
File newFile = new File("src/test/resources/example_new.xml");
File newFile = new File("src/test/resources/example_dom4j_new.xml");
assertTrue(newFile.exists());
parser.setFile(newFile);
Node element = parser.getNodeById("01");
assertEquals("XML with Dom4J", element.selectSingleNode("title").getText());
}
}

View File

@ -12,7 +12,7 @@ import org.junit.Test;
public class JDomParserUnitTest {
final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_jdom.xml";
JDomParser parser;

View File

@ -11,7 +11,7 @@ import com.baeldung.xml.binding.Tutorials;
public class JaxbParserUnitTest {
final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_jaxb.xml";
JaxbParser parser;
@ -27,7 +27,7 @@ public class JaxbParserUnitTest {
@Test
public void createNewDocumentTest() {
File newFile = new File("src/test/resources/example_new.xml");
File newFile = new File("src/test/resources/example_jaxb_new.xml");
parser = new JaxbParser(newFile);
parser.createNewDocument();

View File

@ -10,7 +10,7 @@ import org.junit.Test;
public class JaxenDemoUnitTest {
final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_jaxen.xml";
JaxenDemo jaxenDemo;

View File

@ -12,7 +12,7 @@ import com.baeldung.xml.binding.Tutorial;
public class StaxParserUnitTest {
final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_stax.xml";
StaxParser parser;

0
xml/src/test/resources/Customer1.xml Normal file → Executable file
View File

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<tutorials xmlns="http://www.baeldung.com/full_archive">
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>
<date>04/04/2016</date>
<author>GuavaAuthor</author>
</tutorial>
<tutorial tutId="02" type="java">
<title>XML</title>
<description>Introduction to XPath</description>
<date>04/05/2016</date>
<author>XMLAuthor</author>
</tutorial>
<tutorial tutId="03" type="android">
<title>Android</title>
<description>Introduction to Android</description>
<date>04/03/2016</date>
<author>AndroidAuthor</author>
</tutorial>
<tutorial tutId="04" type="java">
<title>Spring</title>
<description>Introduction to Spring</description>
<date>04/02/2016</date>
<author>SpringAuthor</author>
<sections>
<section name="core">Spring Core</section>
<section name="mvc">Spring MVC</section>
<section name="batch">Spring Batch</section>
</sections>
</tutorial>
</tutorials>

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<tutorials xmlns="http://www.baeldung.com/full_archive">
<tutorials>
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<tutorials>
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>
<date>04/04/2016</date>
<author>GuavaAuthor</author>
</tutorial>
<tutorial tutId="02" type="java">
<title>XML</title>
<description>Introduction to XPath</description>
<date>04/05/2016</date>
<author>XMLAuthor</author>
</tutorial>
<tutorial tutId="03" type="android">
<title>Android</title>
<description>Introduction to Android</description>
<date>04/03/2016</date>
<author>AndroidAuthor</author>
</tutorial>
<tutorial tutId="04" type="java">
<title>Spring</title>
<description>Introduction to Spring</description>
<date>04/02/2016</date>
<author>SpringAuthor</author>
<sections>
<section name="core">Spring Core</section>
<section name="mvc">Spring MVC</section>
<section name="batch">Spring Batch</section>
</sections>
</tutorial>
</tutorials>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<tutorials>
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>
<date>04/04/2016</date>
<author>GuavaAuthor</author>
</tutorial>
<tutorial tutId="02" type="java">
<title>XML</title>
<description>Introduction to XPath</description>
<date>04/05/2016</date>
<author>XMLAuthor</author>
</tutorial>
<tutorial tutId="03" type="android">
<title>Android</title>
<description>Introduction to Android</description>
<date>04/03/2016</date>
<author>AndroidAuthor</author>
</tutorial>
<tutorial tutId="04" type="java">
<title>Spring</title>
<description>Introduction to Spring</description>
<date>04/02/2016</date>
<author>SpringAuthor</author>
<sections>
<section name="core">Spring Core</section>
<section name="mvc">Spring MVC</section>
<section name="batch">Spring Batch</section>
</sections>
</tutorial>
</tutorials>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<tutorials>
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>
<date>04/04/2016</date>
<author>GuavaAuthor</author>
</tutorial>
<tutorial tutId="02" type="java">
<title>XML</title>
<description>Introduction to XPath</description>
<date>04/05/2016</date>
<author>XMLAuthor</author>
</tutorial>
<tutorial tutId="03" type="android">
<title>Android</title>
<description>Introduction to Android</description>
<date>04/03/2016</date>
<author>AndroidAuthor</author>
</tutorial>
<tutorial tutId="04" type="java">
<title>Spring</title>
<description>Introduction to Spring</description>
<date>04/02/2016</date>
<author>SpringAuthor</author>
<sections>
<section name="core">Spring Core</section>
<section name="mvc">Spring MVC</section>
<section name="batch">Spring Batch</section>
</sections>
</tutorial>
</tutorials>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<XMLTutorials>
<tutorial tutId="01" type="xml">
<title>XML with Dom4J</title>
<description>XML handling with Dom4J</description>
<date>14/06/2016</date>
<author>Dom4J tech writer</author>
</tutorial>
</XMLTutorials>

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<tutorials>
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>
<date>04/04/2016</date>
<author>GuavaAuthor</author>
</tutorial>
<tutorial tutId="02" type="java">
<title>XML</title>
<description>Introduction to XPath</description>
<date>04/05/2016</date>
<author>XMLAuthor</author>
</tutorial>
<tutorial tutId="03" type="android">
<title>Android</title>
<description>Introduction to Android</description>
<date>04/03/2016</date>
<author>AndroidAuthor</author>
</tutorial>
<tutorial tutId="04" type="java">
<title>Spring</title>
<description>Introduction to Spring</description>
<date>04/02/2016</date>
<author>SpringAuthor</author>
<sections>
<section name="core">Spring Core</section>
<section name="mvc">Spring MVC</section>
<section name="batch">Spring Batch</section>
</sections>
</tutorial>
</tutorials>