### Question:
HTTPHelper { public static int readChunkLen (@Nonnull @WillNotClose final InputStream aIS) throws IOException { int nRes = 0; boolean bHeadersStarted = false; for (;;) { int ch = aIS.read (); if (ch < 0) throw new EOFException (); if (ch == '\n') break; if (ch >= 'a' && ch <= 'f') ch -= ('a' - 10); else if (ch >= 'A' && ch <= 'F') ch -= ('A' - 10); else if (ch >= '0' && ch <= '9') ch -= '0'; else if (ch == ';') bHeadersStarted = true; else continue; if (!bHeadersStarted) nRes = (nRes * 16) + ch; } return nRes; } private  HTTPHelper(); @Nonnull @ReturnsMutableCopy static ICommonsList <String> getAllHTTPHeaderLines(@Nonnull final InternetHeaders aHeaders); @Nullable static IHTTPIncomingDumper getHTTPIncomingDumper(); @Nonnull static ISupplier <? extends IHTTPIncomingDumper> getHTTPIncomingDumperFactory(); static void setHTTPIncomingDumperFactory(@Nonnull final ISupplier <? extends IHTTPIncomingDumper> aHttpDumperFactory); @Nonnull static DataSource readHttpRequest(@Nonnull final IAS2InputStreamProvider aISP,
                                            @Nonnull final IAS2HttpResponseHandler aResponseHandler,
                                            @Nonnull final IMessage aMsg,
                                            @Nullable final IHTTPIncomingDumper aIncomingDumper); static void sendSimpleHTTPResponse(@Nonnull final IAS2HttpResponseHandler aResponseHandler,
                                             @Nonnegative final int nResponseCode); static int readChunkLen(@Nonnull @WillNotClose final InputStream aIS); static void readTillNexLine(@Nonnull @WillNotClose final InputStream aIS); static final String MA_HTTP_REQ_TYPE; static final String MA_HTTP_REQ_URL; static final String MA_HTTP_REQ_VERSION; }### Answer:
@Test (expected = EOFException.class) public void testReadChunkLenEOS () throws Exception { final InputStream noNewLine = new StringInputStream ("1", StandardCharsets.UTF_8); HTTPHelper.readChunkLen (noNewLine); fail ("An EOFException should have been thrown"); }
@Test public void testReadChunkLenWithHeader () throws Exception { final NonBlockingByteArrayInputStream noNewLine = new NonBlockingByteArrayInputStream ("1A;name=value\r\n".getBytes (StandardCharsets.UTF_8)); final int res = HTTPHelper.readChunkLen (noNewLine); assertEquals ("Chunk size with header", 26, res); }
@Test public void testReadChunkLenNoHeader () throws Exception { final NonBlockingByteArrayInputStream noNewLine = new NonBlockingByteArrayInputStream ("1f\n".getBytes (StandardCharsets.UTF_8)); final int res = HTTPHelper.readChunkLen (noNewLine); assertEquals ("Chunk size with header", 31, res); }
@Test public void testReadChunkLenEmpty () throws Exception { final NonBlockingByteArrayInputStream noNewLine = new NonBlockingByteArrayInputStream ("\n".getBytes (StandardCharsets.UTF_8)); final int res = HTTPHelper.readChunkLen (noNewLine); assertEquals ("Chunk size with header", 0, res); }