From 4d55ecb842fab83e25adfd2cac76bc6b1ba8d0da Mon Sep 17 00:00:00 2001 From: JJ Date: Tue, 27 Dec 2022 22:26:54 -0800 Subject: encapsulation is evil --- src/test/model/html/HtmlParserTest.java | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/test') diff --git a/src/test/model/html/HtmlParserTest.java b/src/test/model/html/HtmlParserTest.java index 879f316..4a35320 100644 --- a/src/test/model/html/HtmlParserTest.java +++ b/src/test/model/html/HtmlParserTest.java @@ -85,10 +85,12 @@ public class HtmlParserTest { */ private static void assertEqualsHtml(ArrayList html, ArrayList expected) { for (int i = 0; i < html.size(); i++) { - assertEquals(html.get(i).getData(), expected.get(i).getData()); + assertEquals(html.get(i).data(), expected.get(i).data()); // System.out.println(html.get(i).getData() + " " + expected.get(i).getData()); - if (html.get(i) instanceof ElementNode) { - assertEqualsHtml(((ElementNode) html.get(i)).getChildren(), ((ElementNode) expected.get(i)).getChildren()); + switch (html.get(i)) { + case ElementNode e -> + assertEqualsHtml(e.children, ((ElementNode) expected.get(i)).children); + default -> {} } } } @@ -99,15 +101,16 @@ public class HtmlParserTest { */ private void displayHtmlTree(ArrayList tree) { for (Node node : tree) { - if (node instanceof ElementNode) { - System.out.print(((ElementNode) node).getTag() + ": "); - for (Node n : ((ElementNode) node).getChildren()) { - System.out.print(n.getData() + " "); + switch (node) { + case ElementNode e -> { + System.out.print(e.tag + ": "); + for (Node n : e.children) { + System.out.print(n.data() + " "); + } + System.out.println(); + displayHtmlTree(e.children); } - System.out.println(); - displayHtmlTree(((ElementNode) node).getChildren()); - } else { - System.out.println("Text: " + node.getData()); + default -> System.out.println("Text: " + node.data()); } } } -- cgit v1.2.3-70-g09d2