BasicLineFormatter implements LineFormatter { @Override public void formatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline) { Args.notNull(buffer, "Char array buffer"); Args.notNull(reqline, "Request line"); buffer.append(reqline.getMethod()); buffer.append(' '); buffer.append(reqline.getUri()); buffer.append(' '); formatProtocolVersion(buffer, reqline.getProtocolVersion()); } BasicLineFormatter(); @Override void formatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline); @Override void formatStatusLine(final CharArrayBuffer buffer, final StatusLine statusLine); @Override void formatHeader(final CharArrayBuffer buffer, final Header header); final static BasicLineFormatter INSTANCE; }
@Test public void testRLFormatting() throws Exception { final RequestLine requestline = new RequestLine(Method.GET.name(), "/stuff", HttpVersion.HTTP_1_1); final CharArrayBuffer buf = new CharArrayBuffer(64); this.formatter.formatRequestLine(buf, requestline); Assert.assertEquals("GET /stuff HTTP/1.1", buf.toString()); }
@Test public void testRLFormattingInvalidInput() throws Exception { final CharArrayBuffer buf = new CharArrayBuffer(64); final RequestLine requestline = new RequestLine(Method.GET.name(), "/stuff", HttpVersion.HTTP_1_1); try { this.formatter.formatRequestLine(null, requestline); Assert.fail("NullPointerException should habe been thrown"); } catch (final NullPointerException ex) { } try { this.formatter.formatRequestLine(buf, null); Assert.fail("NullPointerException should habe been thrown"); } catch (final NullPointerException ex) { } }