### Question:
EuroSubFieldPackager extends ISOBasePackager { @Override public byte[] pack (ISOComponent c) throws ISOException { LogEvent evt = new LogEvent (this, "pack"); try (ByteArrayOutputStream bout = new ByteArrayOutputStream(100)) { Map tab = c.getChildren(); for (Entry ent : (Set<Entry>) tab.entrySet()) { Integer i = (Integer) ent.getKey(); if (i < 0) continue; if (fld[i] == null) throw new ISOException ("Unsupported sub-field " + i + " packing field " + c.getKey()); if (ent.getValue() instanceof ISOComponent) try { ISOComponent f = (ISOComponent) ent.getValue(); byte[] b = fld[i].pack(f); bout.write(b); } catch (Exception e) { evt.addMessage ("error packing subfield "+i); evt.addMessage (c); evt.addMessage (e); throw e; } } byte[] d = bout.toByteArray(); if (logger != null) evt.addMessage (ISOUtil.hexString (d)); return d; } catch (Exception ex) { throw new ISOException (ex); } }  @Override byte[] pack(ISOComponent c); @Override int unpack(ISOComponent m, byte[] b);  }### Answer:
@Test public void testPack() throws Throwable { EuroSubFieldPackager euroSubFieldPackager = new EuroSubFieldPackager(); ISOFieldPackager[] fld = new ISOFieldPackager[4]; euroSubFieldPackager.setFieldPackager(fld); byte[] result = euroSubFieldPackager.pack(new ISOMsg(100)); assertEquals(0, result.length, "result.length"); }
@Test public void testPack3() throws Throwable { EuroSubFieldPackager euroSubFieldPackager = new EuroSubFieldPackager(); ISOFieldPackager[] fld = new ISOFieldPackager[1]; euroSubFieldPackager.setFieldPackager(fld); byte[] result = euroSubFieldPackager.pack(new ISOField()); assertEquals(0, result.length, "result.length"); }
@Test public void testPackThrowsISOException1() throws Throwable { try { new EuroSubFieldPackager().pack(new ISOMsg("testEuroSubFieldPackagerMti")); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertEquals("java.lang.NullPointerException", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested().getMessage(), "ex.getNested().getMessage()"); } else { assertEquals("java.lang.NullPointerException: Cannot load from object array because \"this.fld\" is null", ex.getMessage(), "ex.getMessage()"); assertEquals("Cannot load from object array because \"this.fld\" is null", ex.getNested().getMessage(), "ex.getNested().getMessage()"); } } }
@Test public void testPackThrowsISOException2() throws Throwable { try { new EuroSubFieldPackager().pack(null); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertEquals("java.lang.NullPointerException", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested().getMessage(), "ex.getNested().getMessage()"); } else { assertEquals("java.lang.NullPointerException: Cannot invoke \"org.jpos.iso.ISOComponent.getChildren()\" because \"c\" is null", ex.getMessage(), "ex.getMessage()"); assertEquals("Cannot invoke \"org.jpos.iso.ISOComponent.getChildren()\" because \"c\" is null", ex.getNested().getMessage(), "ex.getNested().getMessage()"); } } }