### Question:
XMLPackager extends DefaultHandler implements ISOPackager, LogSource { public void endElement (String ns, String name, String qname) throws SAXException { if (name.equals (ISOMSG_TAG)) { ISOMsg m = (ISOMsg) stk.pop(); if (stk.empty()) stk.push (m); } else if (ISOFIELD_TAG.equals (name)) { stk.pop(); } else if (HEADER_TAG.equals (name)) { BaseHeader h = (BaseHeader) stk.pop(); ISOMsg m = (ISOMsg) stk.peek (); m.setHeader (h); } } XMLPackager(); void forceBinary(int ... bfields); byte[] pack(ISOComponent c); synchronized int unpack(ISOComponent c, byte[] b); synchronized void unpack(ISOComponent c, InputStream in); void startElement(String ns, String name, String qName, Attributes atts); void characters(char ch[], int start, int length); void endElement(String ns, String name, String qname); String getFieldDescription(ISOComponent m, int fldNumber); void setLogger(Logger logger, String realm); String getRealm(); Logger getLogger(); ISOMsg createISOMsg(); String getDescription(); void setXMLParserFeature(String fname, boolean val); static final String ISOMSG_TAG; static final String ISOFIELD_TAG; static final String ID_ATTR; static final String VALUE_ATTR; static final String TYPE_ATTR; static final String TYPE_BINARY; static final String TYPE_BITMAP; static final String TYPE_AMOUNT; static final String CURRENCY_ATTR; static final String HEADER_TAG; static final String ENCODING_ATTR; static final String ASCII_ENCODING; }### Answer:
@Test public void testEndElementThrowsEmptyStackException() throws Throwable { try { xMLPackager.endElement("testXMLPackagerNs", "header", "testXMLPackagerQname"); fail("Expected EmptyStackException to be thrown"); } catch (EmptyStackException ex) { assertNull(ex.getMessage(), "ex.getMessage()"); } }
@Test public void testEndElementThrowsEmptyStackException1() throws Throwable { try { xMLPackager.endElement("testXMLPackagerNs", "isomsg", "testXMLPackagerQname"); fail("Expected EmptyStackException to be thrown"); } catch (EmptyStackException ex) { assertNull(ex.getMessage(), "ex.getMessage()"); } }
@Test public void testEndElementThrowsNullPointerException() throws Throwable { try { xMLPackager.endElement("testXMLPackagerNs", null, "testXMLPackagerQname"); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"String.equals(Object)\" because \"name\" is null", ex.getMessage(), "ex.getMessage()"); } } }