### Question:
ASCIIChannel extends BaseChannel { protected void sendMessageLength(int len) throws IOException { int maxLen= ten.pow(lengthDigits).intValue() - 1; if (len > maxLen) throw new IOException ("len exceeded ("+len+" > "+maxLen+")"); else if (len < 0) throw new IOException ("invalid negative length ("+len+")"); serverOut.write(ISOUtil.zeropad(len, lengthDigits).getBytes()); } ASCIIChannel();  ASCIIChannel(String host, int port, ISOPackager p);  ASCIIChannel(ISOPackager p);  ASCIIChannel(ISOPackager p, ServerSocket serverSocket); void setLengthDigits(int len); int getLengthDigits(); @Override void setConfiguration(Configuration cfg);  }### Answer:
@Test public void testSendMessageLength() throws Throwable { ASCIIChannel aSCIIChannel = new ASCIIChannel("testASCIIChannelHost", 100, new GenericPackager()); try { aSCIIChannel.sendMessageLength(Integer.MIN_VALUE); fail("IOException expected"); } catch (IOException ex) { assertEquals("invalid negative length ("+Integer.MIN_VALUE+")", ex.getMessage(), "ex.getMessage()"); } }
@Test public void testSendMessageLengthThrowsIOException() throws Throwable { ASCIIChannel aSCIIChannel = new ASCIIChannel(); try { aSCIIChannel.sendMessageLength(10000); fail("Expected IOException to be thrown"); } catch (IOException ex) { assertEquals(IOException.class, ex.getClass(), "ex.getClass()"); } }
@Test public void testSendMessageLengthThrowsNullPointerException() throws Throwable { ASCIIChannel aSCIIChannel = new ASCIIChannel(); try { aSCIIChannel.sendMessageLength(9999); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"java.io.DataOutputStream.write(byte[])\" because \"this.serverOut\" is null", ex.getMessage(), "ex.getMessage()"); } } }
@Test public void testSendMessageLengthThrowsNullPointerException1() throws Throwable { ASCIIChannel aSCIIChannel = new ASCIIChannel(new Base1SubFieldPackager()); try { aSCIIChannel.sendMessageLength(9998); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"java.io.DataOutputStream.write(byte[])\" because \"this.serverOut\" is null", ex.getMessage(), "ex.getMessage()"); } } }