Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Jul 5, 2024
1 parent 0fbdcb7 commit 0969f8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
33 changes: 27 additions & 6 deletions src/test/java/com/nookure/core/inv/test/ActionTest.java
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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;
}
}
9 changes: 4 additions & 5 deletions src/test/java/com/nookure/core/inv/test/XMLParsingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 0969f8a

Please sign in to comment.