### Question:
VISA1Packager extends SimpleLogSource implements ISOPackager, VISA1ResponseFilter { protected int handleSpecialField35 (ISOMsg m, ByteArrayOutputStream bout) throws ISOException, IOException { int len = 0; byte[] entryMode = new byte[1]; if (m.hasField (35)) { entryMode[0] = (byte) '\001'; byte[] value = m.getString(35).getBytes(); bout.write(entryMode); bout.write(value); bout.write(FS); len += value.length+2; } else if (m.hasField (2) && m.hasField (14)) { entryMode[0] = (byte) '\000'; String simulatedTrack2 = m.getString(2) + "=" + m.getString(14); bout.write(entryMode); bout.write(simulatedTrack2.getBytes()); bout.write(FS); len += simulatedTrack2.length()+2; } return len; } VISA1Packager(int[] sequence, int respField, String badResultCode, String okPattern); void setVISA1ResponseFilter(VISA1ResponseFilter filter); @Override byte[] pack(ISOComponent c); String guessAutNumber(String s); @Override int unpack(ISOComponent m, byte[] b); void unpack(ISOComponent m, InputStream in); String getFieldDescription(ISOComponent m, int fldNumber); String getDescription(); ISOMsg createISOMsg(); static final byte[] FS; }### Answer:
@SuppressWarnings("unchecked") @Test public void testHandleSpecialField351() throws Throwable { int[] sequence = new int[0]; VISA1Packager vISA1Packager = new VISA1Packager(sequence, 100, "testVISA1PackagerBadResultCode", "testVISA1PackagerOkPattern"); ByteArrayOutputStream bout = new ByteArrayOutputStream(100); int result = vISA1Packager.handleSpecialField35(new ISOMsg(100), bout); assertEquals(0, result, "result"); }
@SuppressWarnings("unchecked") @Test public void testHandleSpecialField35ThrowsNullPointerException() throws Throwable { int[] sequence = new int[0]; VISA1Packager vISA1Packager = new VISA1Packager(sequence, 100, "testVISA1PackagerBadResultCode", "testVISA1PackagerOkPattern"); ByteArrayOutputStream bout = new ByteArrayOutputStream(100); try { vISA1Packager.handleSpecialField35(null, bout); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.iso.ISOMsg.hasField(int)\" because \"m\" is null", ex.getMessage(), "ex.getMessage()"); } assertEquals(0, bout.toByteArray().length); } }