diff --git a/xml/src/main/java/com/baeldung/xml/JaxbParser.java b/xml/src/main/java/com/baeldung/xml/JaxbParser.java index 9c06ec5fba..758ebb969c 100644 --- a/xml/src/main/java/com/baeldung/xml/JaxbParser.java +++ b/xml/src/main/java/com/baeldung/xml/JaxbParser.java @@ -2,7 +2,6 @@ package com.baeldung.xml; import java.io.File; import java.util.ArrayList; -import java.util.Date; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -40,7 +39,7 @@ public class JaxbParser { tut.setType("XML"); tut.setTitle("XML with Jaxb"); tut.setDescription("XML Binding with Jaxb"); - tut.setDate(new Date()); + tut.setDate("04/02/2015"); tut.setAuthor("Jaxb author"); tutorials.getTutorial().add(tut); diff --git a/xml/src/main/java/com/baeldung/xml/StaxParser.java b/xml/src/main/java/com/baeldung/xml/StaxParser.java index 6f83e022f8..e14d872831 100644 --- a/xml/src/main/java/com/baeldung/xml/StaxParser.java +++ b/xml/src/main/java/com/baeldung/xml/StaxParser.java @@ -17,7 +17,7 @@ import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; -import com.baeldung.xml.model.Tutorial; +import com.baeldung.xml.binding.Tutorial; public class StaxParser { diff --git a/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java b/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java index c4668a9f77..7201d499d0 100644 --- a/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java +++ b/xml/src/main/java/com/baeldung/xml/binding/Tutorial.java @@ -1,7 +1,5 @@ package com.baeldung.xml.binding; -import java.util.Date; - import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -11,7 +9,7 @@ public class Tutorial { private String type; private String title; private String description; - private Date date; + private String date; private String author; @@ -44,11 +42,11 @@ public class Tutorial { public void setDescription(String description) { this.description = description; } - public Date getDate() { + public String getDate() { return date; } @XmlElement - public void setDate(Date date) { + public void setDate(String date) { this.date = date; } public String getAuthor() { diff --git a/xml/src/main/java/com/baeldung/xml/model/Tutorial.java b/xml/src/main/java/com/baeldung/xml/model/Tutorial.java deleted file mode 100644 index 40a3f858cf..0000000000 --- a/xml/src/main/java/com/baeldung/xml/model/Tutorial.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.xml.model; - -public class Tutorial { - - private String tutId; - private String type; - private String title; - private String description; - private String date; - private String author; - - - public String getTutId() { - return tutId; - } - public void setTutId(String tutId) { - this.tutId = tutId; - } - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - public String getDate() { - return date; - } - public void setDate(String date) { - this.date = date; - } - public String getAuthor() { - return author; - } - public void setAuthor(String author) { - this.author = author; - } -} diff --git a/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java b/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java index 7408e41b92..734e7a93cb 100644 --- a/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java +++ b/xml/src/test/java/com/baeldung/xml/DefaultParserTest.java @@ -1,22 +1,20 @@ package com.baeldung.xml; +import static org.junit.Assert.*; + +import java.io.File; + import org.junit.Test; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.io.File; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - public class DefaultParserTest { - private final String fileName = "src/test/resources/example.xml"; + final String fileName = "src/test/resources/example.xml"; - private final String fileNameSpace = "src/test/resources/example_namespace.xml"; + final String fileNameSpace = "src/test/resources/example_namespace.xml"; - private DefaultParser parser; + DefaultParser parser; @Test public void getFirstLevelNodeListTest() { @@ -32,7 +30,7 @@ public class DefaultParserTest { parser = new DefaultParser(new File(fileName)); NodeList list = parser.getNodeListByTitle("XML"); - for (int i = 0; i < list.getLength(); i++) { + for (int i = 0; null != list && i < list.getLength(); i++) { Node nod = list.item(i); assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent()); assertEquals("02", nod.getAttributes().getNamedItem("tutId").getTextContent()); @@ -58,7 +56,7 @@ public class DefaultParserTest { public void getNodeListByDateTest(){ parser = new DefaultParser(new File(fileName)); NodeList list = parser.getNodeListByTitle("04022016"); - for (int i = 0; i < list.getLength(); i++) { + for (int i = 0; null != list && i < list.getLength(); i++) { Node nod = list.item(i); assertEquals("java", nod.getAttributes().getNamedItem("type").getTextContent()); assertEquals("04", nod.getAttributes().getNamedItem("tutId").getTextContent()); diff --git a/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java b/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java index 77e5fcdcda..277eca8355 100644 --- a/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java +++ b/xml/src/test/java/com/baeldung/xml/Dom4JParserTest.java @@ -1,25 +1,25 @@ package com.baeldung.xml; -import org.dom4j.Element; -import org.dom4j.Node; -import org.junit.Test; - -import java.io.File; -import java.util.List; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.util.List; + +import org.dom4j.Element; +import org.dom4j.Node; +import org.junit.Test; + public class Dom4JParserTest { - private static final String FILE_NAME = "src/test/resources/example.xml"; + final String fileName = "src/test/resources/example.xml"; - private Dom4JParser parser; + Dom4JParser parser; @Test public void getRootElementTest() { - parser = new Dom4JParser(new File(FILE_NAME)); + parser = new Dom4JParser(new File(fileName)); Element root = parser.getRootElement(); assertNotNull(root); @@ -28,7 +28,7 @@ public class Dom4JParserTest { @Test public void getFirstElementListTest() { - parser = new Dom4JParser(new File(FILE_NAME)); + parser = new Dom4JParser(new File(fileName)); List firstList = parser.getFirstElementList(); assertNotNull(firstList); @@ -38,7 +38,7 @@ public class Dom4JParserTest { @Test public void getElementByIdTest() { - parser = new Dom4JParser(new File(FILE_NAME)); + parser = new Dom4JParser(new File(fileName)); Node element = parser.getNodeById("03"); String type = element.valueOf("@type"); @@ -47,7 +47,7 @@ public class Dom4JParserTest { @Test public void getElementsListByTitleTest() { - parser = new Dom4JParser(new File(FILE_NAME)); + parser = new Dom4JParser(new File(fileName)); Node element = parser.getElementsListByTitle("XML"); assertEquals("java", element.valueOf("@type")); @@ -58,7 +58,7 @@ public class Dom4JParserTest { @Test public void generateModifiedDocumentTest() { - parser = new Dom4JParser(new File(FILE_NAME)); + parser = new Dom4JParser(new File(fileName)); parser.generateModifiedDocument(); File generatedFile = new File("src/test/resources/example_updated.xml"); @@ -73,7 +73,7 @@ public class Dom4JParserTest { @Test public void generateNewDocumentTest() { - parser = new Dom4JParser(new File(FILE_NAME)); + parser = new Dom4JParser(new File(fileName)); parser.generateNewDocument(); File newFile = new File("src/test/resources/example_new.xml"); diff --git a/xml/src/test/java/com/baeldung/xml/JDomParserTest.java b/xml/src/test/java/com/baeldung/xml/JDomParserTest.java index e4034c48f0..981458469f 100644 --- a/xml/src/test/java/com/baeldung/xml/JDomParserTest.java +++ b/xml/src/test/java/com/baeldung/xml/JDomParserTest.java @@ -1,20 +1,20 @@ package com.baeldung.xml; -import org.jdom2.Element; -import org.junit.Test; - -import java.io.File; -import java.util.List; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.util.List; + +import org.jdom2.Element; +import org.junit.Test; + public class JDomParserTest { - private final String fileName = "src/test/resources/example.xml"; + final String fileName = "src/test/resources/example.xml"; - private JDomParser parser; + JDomParser parser; @Test public void getFirstElementListTest() { diff --git a/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java b/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java index 6e1a201b59..6c31a7bfdd 100644 --- a/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java +++ b/xml/src/test/java/com/baeldung/xml/JaxbParserTest.java @@ -1,19 +1,20 @@ package com.baeldung.xml; -import com.baeldung.xml.binding.Tutorials; -import org.junit.Test; - -import java.io.File; - import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; + +import org.junit.Test; + +import com.baeldung.xml.binding.Tutorials; + public class JaxbParserTest { - private final String fileName = "src/test/resources/example.xml"; + final String fileName = "src/test/resources/example.xml"; - private JaxbParser parser; + JaxbParser parser; @Test public void getFullDocumentTest(){ diff --git a/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java b/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java index 8a88484f11..2521fcaf8a 100644 --- a/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java +++ b/xml/src/test/java/com/baeldung/xml/JaxenDemoTest.java @@ -1,18 +1,18 @@ package com.baeldung.xml; -import org.junit.Test; - -import java.io.File; -import java.util.List; - import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.util.List; + +import org.junit.Test; + public class JaxenDemoTest { - private final String fileName = "src/test/resources/example.xml"; + final String fileName = "src/test/resources/example.xml"; - private JaxenDemo jaxenDemo; + JaxenDemo jaxenDemo; @Test public void getFirstLevelNodeListTest() { diff --git a/xml/src/test/java/com/baeldung/xml/StaxParserTest.java b/xml/src/test/java/com/baeldung/xml/StaxParserTest.java index d1080c88ac..cf7ee1ee75 100644 --- a/xml/src/test/java/com/baeldung/xml/StaxParserTest.java +++ b/xml/src/test/java/com/baeldung/xml/StaxParserTest.java @@ -1,19 +1,20 @@ package com.baeldung.xml; -import com.baeldung.xml.model.Tutorial; -import org.junit.Test; - -import java.io.File; -import java.util.List; - import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; +import java.util.List; + +import org.junit.Test; + +import com.baeldung.xml.binding.Tutorial; + public class StaxParserTest { - private final String fileName = "src/test/resources/example.xml"; + final String fileName = "src/test/resources/example.xml"; - private StaxParser parser; + StaxParser parser; @Test public void getAllTutorialsTest(){