BAEL-952 Removed mutable state by having separate files for tests (#1994)
This commit is contained in:
parent
ecc91a6108
commit
97c1291359
4
xml/src/main/java/com/baeldung/xml/Dom4JParser.java
Normal file → Executable file
4
xml/src/main/java/com/baeldung/xml/Dom4JParser.java
Normal file → Executable file
@ -82,7 +82,7 @@ public class Dom4JParser {
|
|||||||
title.setText(title.getText() + " updated");
|
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.write(document);
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (DocumentException e) {
|
} catch (DocumentException e) {
|
||||||
@ -110,7 +110,7 @@ public class Dom4JParser {
|
|||||||
tutorialElement.addElement("author").addText("Dom4J tech writer");
|
tutorialElement.addElement("author").addText("Dom4J tech writer");
|
||||||
|
|
||||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
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.write(document);
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
8
xml/src/test/java/com/baeldung/xml/DefaultParserUnitTest.java
Normal file → Executable file
8
xml/src/test/java/com/baeldung/xml/DefaultParserUnitTest.java
Normal file → Executable file
@ -1,6 +1,8 @@
|
|||||||
package com.baeldung.xml;
|
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;
|
import java.io.File;
|
||||||
|
|
||||||
@ -10,9 +12,9 @@ import org.w3c.dom.NodeList;
|
|||||||
|
|
||||||
public class DefaultParserUnitTest {
|
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;
|
DefaultParser parser;
|
||||||
|
|
||||||
|
7
xml/src/test/java/com/baeldung/xml/Dom4JParserUnitTest.java
Normal file → Executable file
7
xml/src/test/java/com/baeldung/xml/Dom4JParserUnitTest.java
Normal file → Executable file
@ -13,7 +13,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class Dom4JParserUnitTest {
|
public class Dom4JParserUnitTest {
|
||||||
|
|
||||||
final String fileName = "src/test/resources/example.xml";
|
final String fileName = "src/test/resources/example_dom4j.xml";
|
||||||
|
|
||||||
Dom4JParser parser;
|
Dom4JParser parser;
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public class Dom4JParserUnitTest {
|
|||||||
parser = new Dom4JParser(new File(fileName));
|
parser = new Dom4JParser(new File(fileName));
|
||||||
parser.generateModifiedDocument();
|
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());
|
assertTrue(generatedFile.exists());
|
||||||
|
|
||||||
parser.setFile(generatedFile);
|
parser.setFile(generatedFile);
|
||||||
@ -76,13 +76,12 @@ public class Dom4JParserUnitTest {
|
|||||||
parser = new Dom4JParser(new File(fileName));
|
parser = new Dom4JParser(new File(fileName));
|
||||||
parser.generateNewDocument();
|
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());
|
assertTrue(newFile.exists());
|
||||||
|
|
||||||
parser.setFile(newFile);
|
parser.setFile(newFile);
|
||||||
Node element = parser.getNodeById("01");
|
Node element = parser.getNodeById("01");
|
||||||
|
|
||||||
assertEquals("XML with Dom4J", element.selectSingleNode("title").getText());
|
assertEquals("XML with Dom4J", element.selectSingleNode("title").getText());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
xml/src/test/java/com/baeldung/xml/JDomParserUnitTest.java
Normal file → Executable file
2
xml/src/test/java/com/baeldung/xml/JDomParserUnitTest.java
Normal file → Executable file
@ -12,7 +12,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class JDomParserUnitTest {
|
public class JDomParserUnitTest {
|
||||||
|
|
||||||
final String fileName = "src/test/resources/example.xml";
|
final String fileName = "src/test/resources/example_jdom.xml";
|
||||||
|
|
||||||
JDomParser parser;
|
JDomParser parser;
|
||||||
|
|
||||||
|
4
xml/src/test/java/com/baeldung/xml/JaxbParserUnitTest.java
Normal file → Executable file
4
xml/src/test/java/com/baeldung/xml/JaxbParserUnitTest.java
Normal file → Executable file
@ -11,7 +11,7 @@ import com.baeldung.xml.binding.Tutorials;
|
|||||||
|
|
||||||
public class JaxbParserUnitTest {
|
public class JaxbParserUnitTest {
|
||||||
|
|
||||||
final String fileName = "src/test/resources/example.xml";
|
final String fileName = "src/test/resources/example_jaxb.xml";
|
||||||
|
|
||||||
JaxbParser parser;
|
JaxbParser parser;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class JaxbParserUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createNewDocumentTest() {
|
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 = new JaxbParser(newFile);
|
||||||
parser.createNewDocument();
|
parser.createNewDocument();
|
||||||
|
|
||||||
|
2
xml/src/test/java/com/baeldung/xml/JaxenDemoUnitTest.java
Normal file → Executable file
2
xml/src/test/java/com/baeldung/xml/JaxenDemoUnitTest.java
Normal file → Executable file
@ -10,7 +10,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class JaxenDemoUnitTest {
|
public class JaxenDemoUnitTest {
|
||||||
|
|
||||||
final String fileName = "src/test/resources/example.xml";
|
final String fileName = "src/test/resources/example_jaxen.xml";
|
||||||
|
|
||||||
JaxenDemo jaxenDemo;
|
JaxenDemo jaxenDemo;
|
||||||
|
|
||||||
|
2
xml/src/test/java/com/baeldung/xml/StaxParserUnitTest.java
Normal file → Executable file
2
xml/src/test/java/com/baeldung/xml/StaxParserUnitTest.java
Normal file → Executable file
@ -12,7 +12,7 @@ import com.baeldung.xml.binding.Tutorial;
|
|||||||
|
|
||||||
public class StaxParserUnitTest {
|
public class StaxParserUnitTest {
|
||||||
|
|
||||||
final String fileName = "src/test/resources/example.xml";
|
final String fileName = "src/test/resources/example_stax.xml";
|
||||||
|
|
||||||
StaxParser parser;
|
StaxParser parser;
|
||||||
|
|
||||||
|
0
xml/src/test/resources/Customer1.xml
Normal file → Executable file
0
xml/src/test/resources/Customer1.xml
Normal file → Executable file
0
xml/src/test/resources/example.xml → xml/src/test/resources/example_default_parser.xml
Normal file → Executable file
0
xml/src/test/resources/example.xml → xml/src/test/resources/example_default_parser.xml
Normal file → Executable file
32
xml/src/test/resources/example_default_parser_namespace.xml
Normal file
32
xml/src/test/resources/example_default_parser_namespace.xml
Normal 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>
|
4
xml/src/test/resources/example_namespace.xml → xml/src/test/resources/example_dom4j.xml
Normal file → Executable file
4
xml/src/test/resources/example_namespace.xml → xml/src/test/resources/example_dom4j.xml
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<tutorials xmlns="http://www.baeldung.com/full_archive">
|
<tutorials>
|
||||||
<tutorial tutId="01" type="java">
|
<tutorial tutId="01" type="java">
|
||||||
<title>Guava</title>
|
<title>Guava</title>
|
||||||
<description>Introduction to Guava</description>
|
<description>Introduction to Guava</description>
|
||||||
<date>04/04/2016</date>
|
<date>04/04/2016</date>
|
0
xml/src/test/resources/example_updated.xml → xml/src/test/resources/example_dom4j_updated.xml
Normal file → Executable file
0
xml/src/test/resources/example_updated.xml → xml/src/test/resources/example_dom4j_updated.xml
Normal file → Executable file
32
xml/src/test/resources/example_jaxb.xml
Executable file
32
xml/src/test/resources/example_jaxb.xml
Executable 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>
|
32
xml/src/test/resources/example_jaxen.xml
Executable file
32
xml/src/test/resources/example_jaxen.xml
Executable 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>
|
32
xml/src/test/resources/example_jdom.xml
Executable file
32
xml/src/test/resources/example_jdom.xml
Executable 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>
|
@ -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>
|
|
32
xml/src/test/resources/example_stax.xml
Executable file
32
xml/src/test/resources/example_stax.xml
Executable 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>
|
Loading…
x
Reference in New Issue
Block a user