diff --git a/src/test/java/com/nookure/core/inv/test/ActionTest.java b/src/test/java/com/nookure/core/inv/test/ActionTest.java index fc7aff6..411fbf7 100644 --- a/src/test/java/com/nookure/core/inv/test/ActionTest.java +++ b/src/test/java/com/nookure/core/inv/test/ActionTest.java @@ -1,23 +1,25 @@ package com.nookure.core.inv.test; +import com.nookure.core.inv.NookureInventoryEngine; import com.nookure.core.inv.parser.GuiLayout; import com.nookure.core.inv.parser.item.Action; import com.nookure.core.inv.parser.item.Item; +import io.pebbletemplates.pebble.loader.StringLoader; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Unmarshaller; import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; -import java.io.InputStream; +import javax.xml.parsers.ParserConfigurationException; +import java.io.*; +import java.nio.charset.StandardCharsets; public class ActionTest { private static final InputStream xmlStream = XMLParsingTest.class.getClassLoader().getResourceAsStream("GuiLayoutTest.xml"); @Test - public void action() throws JAXBException { - JAXBContext context = JAXBContext.newInstance(GuiLayout.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - - GuiLayout guiLayout = (GuiLayout) unmarshaller.unmarshal(xmlStream); + public void action() throws JAXBException, ParserConfigurationException, SAXException { + GuiLayout guiLayout = guiLayout(xmlStream); System.out.println("Title: " + guiLayout.head().title().title()); System.out.println("Title tl: " + guiLayout.head().title().tl()); @@ -42,4 +44,23 @@ public void action() throws JAXBException { } } } + + public static GuiLayout guiLayout(InputStream xmlStream) throws JAXBException, ParserConfigurationException, SAXException { + NookureInventoryEngine engine = new NookureInventoryEngine(new StringLoader()); + StringBuilder textBuilder = new StringBuilder(); + assert xmlStream != null; + + try (Reader reader = new BufferedReader(new InputStreamReader + (xmlStream, StandardCharsets.UTF_8))) { + int c = 0; + while ((c = reader.read()) != -1) { + textBuilder.append((char) c); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + + GuiLayout guiLayout = engine.parseLayout(textBuilder.toString()); + return guiLayout; + } } diff --git a/src/test/java/com/nookure/core/inv/test/XMLParsingTest.java b/src/test/java/com/nookure/core/inv/test/XMLParsingTest.java index ee3e871..20e7379 100644 --- a/src/test/java/com/nookure/core/inv/test/XMLParsingTest.java +++ b/src/test/java/com/nookure/core/inv/test/XMLParsingTest.java @@ -6,18 +6,17 @@ import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Unmarshaller; import org.junit.jupiter.api.Test; +import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.InputStream; public class XMLParsingTest { private static final InputStream xmlStream = XMLParsingTest.class.getClassLoader().getResourceAsStream("GuiLayoutTest.xml"); @Test - public void xmlTest() throws JAXBException { - JAXBContext context = JAXBContext.newInstance(GuiLayout.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - - GuiLayout guiLayout = (GuiLayout) unmarshaller.unmarshal(xmlStream); + public void xmlTest() throws JAXBException, ParserConfigurationException, SAXException { + GuiLayout guiLayout = ActionTest.guiLayout(xmlStream); System.out.println("Title: " + guiLayout.head().title().title()); System.out.println("Title tl: " + guiLayout.head().title().tl());