Skip to content

Commit

Permalink
BAEL-952 Removed mutable state by having separate files for tests (eu…
Browse files Browse the repository at this point in the history
  • Loading branch information
khatwaniNikhil authored and pedja4 committed Jun 5, 2017
1 parent ecc91a6 commit 97c1291
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 26 deletions.
4 changes: 2 additions & 2 deletions xml/src/main/java/com/baeldung/xml/Dom4JParser.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void generateModifiedDocument() {
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) {
Expand Down Expand Up @@ -110,7 +110,7 @@ public void generateNewDocument() {
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) {
Expand Down
8 changes: 5 additions & 3 deletions xml/src/test/java/com/baeldung/xml/DefaultParserUnitTest.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -10,9 +12,9 @@

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;

Expand Down
7 changes: 3 additions & 4 deletions xml/src/test/java/com/baeldung/xml/Dom4JParserUnitTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class Dom4JParserUnitTest {

final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_dom4j.xml";

Dom4JParser parser;

Expand Down Expand Up @@ -61,7 +61,7 @@ public void generateModifiedDocumentTest() {
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);
Expand All @@ -76,13 +76,12 @@ public void generateNewDocumentTest() {
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());

}
}
2 changes: 1 addition & 1 deletion xml/src/test/java/com/baeldung/xml/JDomParserUnitTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class JDomParserUnitTest {

final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_jdom.xml";

JDomParser parser;

Expand Down
4 changes: 2 additions & 2 deletions xml/src/test/java/com/baeldung/xml/JaxbParserUnitTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class JaxbParserUnitTest {

final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_jaxb.xml";

JaxbParser parser;

Expand All @@ -27,7 +27,7 @@ public void getFullDocumentTest() {

@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();

Expand Down
2 changes: 1 addition & 1 deletion xml/src/test/java/com/baeldung/xml/JaxenDemoUnitTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class JaxenDemoUnitTest {

final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_jaxen.xml";

JaxenDemo jaxenDemo;

Expand Down
2 changes: 1 addition & 1 deletion xml/src/test/java/com/baeldung/xml/StaxParserUnitTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class StaxParserUnitTest {

final String fileName = "src/test/resources/example.xml";
final String fileName = "src/test/resources/example_stax.xml";

StaxParser parser;

Expand Down
Empty file modified xml/src/test/resources/Customer1.xml
100644 → 100755
Empty file.
File renamed without changes.
32 changes: 32 additions & 0 deletions xml/src/test/resources/example_default_parser_namespace.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<tutorials xmlns="http://www.baeldung.com/full_archive">
<tutorial tutId="01" type="java">
<tutorials>
<tutorial tutId="01" type="java">
<title>Guava</title>
<description>Introduction to Guava</description>
<date>04/04/2016</date>
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions xml/src/test/resources/example_jaxb.xml
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions xml/src/test/resources/example_jaxen.xml
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions xml/src/test/resources/example_jdom.xml
Original file line number Diff line number Diff line change
@@ -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>
10 changes: 0 additions & 10 deletions xml/src/test/resources/example_new.xml

This file was deleted.

32 changes: 32 additions & 0 deletions xml/src/test/resources/example_stax.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 97c1291

Please sign in to comment.