### Question:
BASE1Header extends BaseHeader { public void setLen(int len) { len += header.length; header[3] = (byte) (len >> 8 & 0xff); header[4] = (byte) (len & 0xff); } BASE1Header();  BASE1Header(String source, String destination);  BASE1Header(String source, String destination, int format);  BASE1Header(byte[] header); int getHLen(); void setHFormat(int hformat); int getFormat(); void setRtCtl(int i); void setFlags(int i); void setStatus(int i); void setBatchNumber(int i); void setFormat(int format); void setLen(int len); void setDestination(String dest); void setSource(String src); String getSource(); String getDestination(); void swapDirection(); boolean isRejected(); String getRejectCode(); String formatHeader(); static final int LENGTH; }### Answer:
@Test public void testSetLen() throws Throwable { BASE1Header bASE1Header = new BASE1Header(); bASE1Header.setLen(100); assertEquals(22, bASE1Header.header.length, "bASE1Header.header.length"); }
@Test public void testSetLenThrowsArrayIndexOutOfBoundsException() throws Throwable { BASE1Header bASE1Header = new BASE1Header("testBASE1HeaderSource", "testBASE1HeaderDestination"); byte[] header = new byte[4]; bASE1Header.unpack(header); try { bASE1Header.setLen(100); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertEquals("4", ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Index 4 out of bounds for length 4", ex.getMessage(), "ex.getMessage()"); } assertTrue(Arrays.equals(header, bASE1Header.header), "bASE1Header.header"); } }
@Test public void testSetLenThrowsArrayIndexOutOfBoundsException1() throws Throwable { BASE1Header clone = (BASE1Header) new BASE1Header("testBASE1HeaderSource", "testBASE1HeaderDestination").clone(); byte[] header = new byte[3]; clone.unpack(header); try { clone.setLen(100); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertEquals("3", ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Index 3 out of bounds for length 3", ex.getMessage(), "ex.getMessage()"); } assertTrue(Arrays.equals(header, clone.header), "clone.header"); } }