### Question:
BASE1Header extends BaseHeader { public void setFlags(int i) { header[12] = (byte) (i >> 8 & 0xFF); header[13] = (byte) (i & 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 testSetFlags() throws Throwable { BASE1Header bASE1Header = new BASE1Header(); bASE1Header.setFlags(100); assertEquals(22, bASE1Header.header.length, "bASE1Header.header.length"); }
@Test public void testSetFlagsThrowsArrayIndexOutOfBoundsException() throws Throwable { byte[] header = new byte[9]; BASE1Header bASE1Header = new BASE1Header(); bASE1Header.unpack(header); try { bASE1Header.setFlags(100); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertEquals("12", ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Index 12 out of bounds for length 9", ex.getMessage(), "ex.getMessage()"); } assertTrue(Arrays.equals(header, bASE1Header.header), "bASE1Header.header"); } }
@Test public void testSetFlagsThrowsArrayIndexOutOfBoundsException1() throws Throwable { byte[] header = new byte[13]; BASE1Header bASE1Header = new BASE1Header(); bASE1Header.unpack(header); try { bASE1Header.setFlags(100); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { if (isJavaVersionAtMost(JAVA_10)) { assertEquals("13", ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Index 13 out of bounds for length 13", ex.getMessage(), "ex.getMessage()"); } assertNotEquals(header, bASE1Header.header, "bASE1Header.header"); } }