From b250d243c4fc425ff37d90a5996432c8037bf364 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Sun, 27 Dec 2020 14:03:07 +0100 Subject: [PATCH] fixed the unit test for the xml helper --- .../com/example/aped/XMLHandlerUnitTest.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java b/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java index 048a907..6f2f331 100644 --- a/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java +++ b/APED/app/src/test/java/com/example/aped/XMLHandlerUnitTest.java @@ -5,6 +5,7 @@ import com.example.aped.utils.XMLHandler; import org.junit.Test; import org.xml.sax.SAXException; +import java.io.File; import java.io.IOException; import java.util.Dictionary; import java.util.List; @@ -14,13 +15,15 @@ import javax.xml.parsers.ParserConfigurationException; import static org.junit.Assert.*; public class XMLHandlerUnitTest { - private String xmlPath="src/main/java/com/example/aped/xml/Test.xml"; - private String xsdPath="src/main/java/com/example/aped/xml/config.xsd"; + private String xmlPath="src/main/res/raw/XML/Test.xml"; + private String xsdPath="src/main/res/raw/XML/config.xsd"; + private File xmlFile = new File(xmlPath); + private File xsdFile = new File(xsdPath); @Test public void TestFiles_AreValid(){ try{ - XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath); + XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile); }catch(IOException | ParserConfigurationException | SAXException e){ System.out.println("XMLHandler failed"); assert(false); @@ -33,7 +36,7 @@ public class XMLHandlerUnitTest { @Test public void Test_getDeviceNames(){ try{ - XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath); + XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile); List deviceNames = xmlHandler.getDeviceNames(); assertArrayEquals(new String[]{"example","sensorarray"},deviceNames.toArray()); }catch(IOException | ParserConfigurationException | SAXException e){ @@ -45,7 +48,7 @@ public class XMLHandlerUnitTest { @Test public void TestInput_SimpleValueInfo(){ try{ - XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath); + XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile); Dictionary valueInfo = xmlHandler.getValueInfo("example"); assertEquals("{factor=1.0, type=boolean, unit=, offset=0.0}",valueInfo.toString()); }catch(IOException | ParserConfigurationException | SAXException e){ @@ -57,7 +60,7 @@ public class XMLHandlerUnitTest { @Test public void TestInput_ComplexValueInfo(){ try{ - XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath); + XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile); Dictionary valueInfo = xmlHandler.getValueInfo("sensorarray"); assertEquals("{factor=2.5, type=int, unit=°C, offset=1.2}",valueInfo.toString()); }catch(IOException | ParserConfigurationException | SAXException e){ @@ -69,7 +72,7 @@ public class XMLHandlerUnitTest { @Test public void TestInput_SimplePort(){ try{ - XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath); + XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile); Dictionary port = xmlHandler.getPort("example"); assertEquals("{pins=[GPIO_2], protocol=DI}",port.toString()); }catch(IOException | ParserConfigurationException | SAXException e){ @@ -81,7 +84,7 @@ public class XMLHandlerUnitTest { @Test public void TestInput_ComplexPort(){ try{ - XMLHandler xmlHandler = new XMLHandler(xmlPath,xsdPath); + XMLHandler xmlHandler = new XMLHandler(xmlFile,xsdFile); Dictionary port = xmlHandler.getPort("sensorarray"); assertEquals("{pins=[GPIO_3, GPIO_4, GPIO_5, GPIO_6], protocol=DI}",port.toString()); }catch(IOException | ParserConfigurationException | SAXException e){