From 2aa8d73e234ffd91990187e6bd733c5aa514cff1 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 2 Mar 2016 18:40:00 +0000 Subject: Throw more information exception when attribute is missing --- .../zwobble/mammoth/tests/xml/XmlElementTests.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/org/zwobble/mammoth/tests/xml/XmlElementTests.java (limited to 'src/test') diff --git a/src/test/java/org/zwobble/mammoth/tests/xml/XmlElementTests.java b/src/test/java/org/zwobble/mammoth/tests/xml/XmlElementTests.java new file mode 100644 index 0000000..f396b1b --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/xml/XmlElementTests.java @@ -0,0 +1,21 @@ +package org.zwobble.mammoth.tests.xml; + +import org.junit.Test; +import org.zwobble.mammoth.internal.xml.XmlElement; +import org.zwobble.mammoth.internal.xml.XmlNodes; + +import static org.junit.Assert.assertEquals; +import static org.zwobble.mammoth.tests.util.MammothAsserts.assertThrows; + +public class XmlElementTests { + @Test + public void TryingToGetNonExistentAttributeThrowsException() { + XmlElement element = XmlNodes.element("p"); + + RuntimeException exception = assertThrows( + RuntimeException.class, + () -> element.getAttribute("class")); + + assertEquals("Element has no 'class' attribute", exception.getMessage()); + } +} -- cgit v1.2.3