### Question:
CTCSubFieldPackager extends ISOBaseValidatingPackager { public byte[] pack ( ISOComponent c ) throws ISOException { try { Map tab = c.getChildren(); StringBuilder sb = new StringBuilder(); for ( int i = 0; i < fld.length; i++ ) { ISOField f = (ISOField) tab.get (i); if ( f != null ) { sb.append ( new String( fld[i].pack( f ) ) ); } } return sb.toString().getBytes(); } catch ( Exception ex ) { throw new ISOException ( this.getRealm() + ": " + ex.getMessage(), ex ); } } CTCSubFieldPackager(); byte[] pack( ISOComponent c ); int unpack( ISOComponent m, byte[] b ); ISOComponent validate( ISOComponent c );  }### Answer:
@Test public void testPack1() throws Throwable { CTCSubFieldPackager cTCSubFieldPackager = new CTCSubFieldPackager(); ISOFieldPackager[] fld = new ISOFieldPackager[1]; cTCSubFieldPackager.setFieldPackager(fld); byte[] result = cTCSubFieldPackager.pack(new ISOField()); assertEquals(0, result.length, "result.length"); }
@Test public void testPackThrowsISOException() throws Throwable { try { new CTCSubFieldPackager().pack(null); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertEquals("null: null", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested().getMessage(), "ex.getNested().getMessage()"); } else { assertEquals("null: 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()"); } } }
@Test public void testPackThrowsISOException1() throws Throwable { try { new CTCSubFieldPackager().pack(new ISOBinaryField(100)); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertEquals("null: null", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested().getMessage(), "ex.getNested().getMessage()"); } else { assertEquals("null: Cannot read the array length because \"this.fld\" is null", ex.getMessage(), "ex.getMessage()"); assertEquals("Cannot read the array length because \"this.fld\" is null", ex.getNested().getMessage(), "ex.getNested().getMessage()"); } } }
@Test public void testPackThrowsISOException2() throws Throwable { CTCSubFieldPackager cTCSubFieldPackager = new CTCSubFieldPackager(); ISOFieldPackager[] fld = new ISOFieldPackager[1]; cTCSubFieldPackager.setFieldPackager(fld); try { cTCSubFieldPackager.pack(new ISOMsg("testCTCSubFieldPackagerMti")); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertEquals("null: null", ex.getMessage(), "ex.getMessage()"); assertNull(ex.getNested().getMessage(), "ex.getNested().getMessage()"); } else { assertEquals("null: Cannot invoke \"org.jpos.iso.ISOFieldPackager.pack(org.jpos.iso.ISOComponent)\" because \"this.fld[i]\" is null", ex.getMessage(), "ex.getMessage()"); assertEquals("Cannot invoke \"org.jpos.iso.ISOFieldPackager.pack(org.jpos.iso.ISOComponent)\" because \"this.fld[i]\" is null", ex.getNested().getMessage(), "ex.getNested().getMessage()"); } } }