From 4065ece67158a6658f0640c53e664fbfa370005e Mon Sep 17 00:00:00 2001 From: Chinmoy Chakraborty Date: Thu, 18 May 2023 14:34:11 +0530 Subject: [PATCH] Fixed failing tests. --- .../messagerosa/utils/ResourcePathHelper.java | 2 +- .../messagerosa/xml/ElementParserTest.java | 38 ------------------- .../messagerosa/xml/XMessageParserTest.java | 13 +++---- .../xml/testMessage.xml | 0 4 files changed, 6 insertions(+), 47 deletions(-) delete mode 100644 src/test/java/messagerosa/xml/ElementParserTest.java rename src/test/{java/messagerosa => resources}/xml/testMessage.xml (100%) diff --git a/src/test/java/messagerosa/utils/ResourcePathHelper.java b/src/test/java/messagerosa/utils/ResourcePathHelper.java index 8afbf7f..f4f32bf 100644 --- a/src/test/java/messagerosa/utils/ResourcePathHelper.java +++ b/src/test/java/messagerosa/utils/ResourcePathHelper.java @@ -16,7 +16,7 @@ public class ResourcePathHelper { private static synchronized Set buildCache() { try { - URI uri = ResourcePathHelper.class.getResource("/testMessage.xml").toURI(); + URI uri = ResourcePathHelper.class.getResource("/xml/testMessage.xml").toURI(); Path root = Paths.get(uri).getParent(); return walk(root) .filter(p -> isRegularFile(p)) diff --git a/src/test/java/messagerosa/xml/ElementParserTest.java b/src/test/java/messagerosa/xml/ElementParserTest.java deleted file mode 100644 index 617ac76..0000000 --- a/src/test/java/messagerosa/xml/ElementParserTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package messagerosa.xml; - -import messagerosa.core.model.XMessage; -import messagerosa.xml.exception.InvalidStructureException; -import org.junit.Before; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.kxml2.io.KXmlParser; -import org.xmlpull.v1.XmlPullParserException; - -import javax.xml.bind.JAXBException; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Path; -import java.nio.file.Paths; - -import static junit.framework.TestCase.assertEquals; -import static messagerosa.utils.ResourcePathHelper.r; -import static org.junit.jupiter.api.Assertions.*; - -class ElementParserTest { - - private static Path PRIMARY_XMESSAGE_PATH; - - @Before - public void setUp() { - PRIMARY_XMESSAGE_PATH = r("testMessage.xml"); - } - - @Test - public void parseInternalInstances() throws IOException, JAXBException { - InputStream inputStream = new FileInputStream("/Users/apple/chaks/experiments/java/comms/message-rosa/src/test/java/messagerosa/xml/" +"testMessage.xml"); - XMessage message = XMessageParser.parse(inputStream); - Assertions.assertEquals(1, 1); - } -} \ No newline at end of file diff --git a/src/test/java/messagerosa/xml/XMessageParserTest.java b/src/test/java/messagerosa/xml/XMessageParserTest.java index 7133273..b7502e9 100644 --- a/src/test/java/messagerosa/xml/XMessageParserTest.java +++ b/src/test/java/messagerosa/xml/XMessageParserTest.java @@ -1,11 +1,9 @@ package messagerosa.xml; -import messagerosa.core.model.XMessage; import org.junit.jupiter.api.Test; -import javax.xml.bind.JAXBException; import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import static org.junit.jupiter.api.Assertions.*; @@ -13,10 +11,9 @@ class XMessageParserTest { @Test - void parse() throws FileNotFoundException, JAXBException { - InputStream inputStream = new FileInputStream("~/message-rosa/src/test/java/messagerosa/xml/" + "testMessage.xml"); - XMessage message = XMessageParser.parse(inputStream); - System.out.println(message.toXML()); - assertEquals(1, 1); + void parse() throws IOException { + try (InputStream inputStream = new FileInputStream("src/test/resources/xml/" + "testMessage.xml")) { + assertDoesNotThrow(() -> XMessageParser.parse(inputStream)); + } } } \ No newline at end of file diff --git a/src/test/java/messagerosa/xml/testMessage.xml b/src/test/resources/xml/testMessage.xml similarity index 100% rename from src/test/java/messagerosa/xml/testMessage.xml rename to src/test/resources/xml/testMessage.xml