### Question:
FSDMsg implements Loggeable, Cloneable { public String pack () throws JDOMException, IOException, ISOException { StringBuilder sb = new StringBuilder (); pack (getSchema (baseSchema), sb); return sb.toString (); } FSDMsg(String basePath);  FSDMsg(String basePath, String baseSchema); String getBasePath(); String getBaseSchema(); void setCharset(Charset charset); void setSeparator(String separatorName, char separator); void unsetSeparator(String separatorName); void unpack(InputStream is); void unpack(byte[] b); String pack(); byte[] packToBytes(); boolean isSeparator(byte b); void set(String name, String value); void setHeader(byte[] h); byte[] getHeader(); String getHexHeader(); String get(String fieldName); String get(String fieldName, String def); void copy(String fieldName, FSDMsg msg); void copy(String fieldName, FSDMsg msg, String def); byte[] getHexBytes(String name); @SuppressWarnings("PMD.EmptyCatchBlock") int getInt(String name); @SuppressWarnings("PMD.EmptyCatchBlock") int getInt(String name, int def); Element toXML(); Map getMap(); void setMap(Map fields); @Override void dump(PrintStream p, String indent); boolean hasField(String fieldName); @Override Object clone(); void merge(FSDMsg m); @Override boolean equals(Object o); @Override int hashCode(); static char FS; static char US; static char GS; static char RS; static char EOF; static char PIPE; static char EOM; }### Answer:
@Test public void testPack() throws Throwable { Element schema = new FSDMsg("testFSDMsgBasePath").toXML(); FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); StringBuilder sb = new StringBuilder(); fSDMsg.pack(schema, sb); assertEquals(0, fSDMsg.fields.size(), "fSDMsg.fields.size()"); assertEquals("message", schema.getName(), "schema.getName()"); assertEquals("", sb.toString(), "sb.toString()"); }
@Test public void testPackThrowsMalformedURLException() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); try { fSDMsg.pack(); fail("Expected MalformedURLException to be thrown"); } catch (MalformedURLException ex) { assertEquals(MalformedURLException.class, ex.getClass(), "ex.getClass()"); assertEquals(0, fSDMsg.fields.size(), "fSDMsg.fields.size()"); assertEquals("testFSDMsgBaseSchema", fSDMsg.baseSchema, "fSDMsg.baseSchema"); } }
@Test public void testPackThrowsNullPointerException() throws Throwable { FSDMsg fSDMsg = new FSDMsg(null, "testFSDMsgBaseSchema"); try { fSDMsg.pack(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertEquals("basePath can not be null", ex.getMessage(), "ex.getMessage()"); assertEquals(0, fSDMsg.fields.size(), "fSDMsg.fields.size()"); assertEquals("testFSDMsgBaseSchema", fSDMsg.baseSchema, "fSDMsg.baseSchema"); } }
@Test public void testPackThrowsNullPointerException1() throws Throwable { StringBuilder sb = new StringBuilder(); FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); try { fSDMsg.pack(null, sb); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jdom2.Element.getChildren(String)\" because \"schema\" is null", ex.getMessage(), "ex.getMessage()"); } assertEquals(0, fSDMsg.fields.size(), "fSDMsg.fields.size()"); assertEquals("", sb.toString(), "sb.toString()"); } }