Code example for CharArrayBuffer

Methods: append, clear, ensureCapacity

0
                (new CharArrayBuffer(10), (HttpVersion) null);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
    } 
 
 
    public void testRLFormatting() throws Exception { 
        RequestLine requestline = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
        String s = BasicLineFormatter.formatRequestLine(requestline, null);
        assertEquals("GET /stuff HTTP/1.1", s);
    } 
 
    public void testRLFormattingInvalidInput() throws Exception { 
        try { 
            BasicLineFormatter.formatRequestLine
                (null, BasicLineFormatter.DEFAULT);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
        try { 
            BasicLineFormatter.DEFAULT.formatRequestLine
                (new CharArrayBuffer(10), (RequestLine) null);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
    } 
 
 
 
    public void testSLFormatting() throws Exception { 
        StatusLine statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
        String s = BasicLineFormatter.formatStatusLine(statusline, null);
        assertEquals("HTTP/1.1 200 OK", s);
        statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null);
        s = BasicLineFormatter.formatStatusLine(statusline, null);
        assertEquals("HTTP/1.1 200 ", s);
        // see "testSLParseSuccess" in TestBasicLineParser: 
        // trailing space is correct 
    } 
 
    public void testSLFormattingInvalidInput() throws Exception { 
        try { 
            BasicLineFormatter.formatStatusLine
                (null, BasicLineFormatter.DEFAULT);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
        try { 
            BasicLineFormatter.DEFAULT.formatStatusLine
                (new CharArrayBuffer(10), (StatusLine) null);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
    } 
 
 
    public void testHeaderFormatting() throws Exception { 
        Header header1 = new BasicHeader("name", "value");
        String s = BasicLineFormatter.formatHeader(header1, null);
        assertEquals("name: value", s);
        Header header2 = new BasicHeader("name", null);
        s = BasicLineFormatter.formatHeader(header2, null);
        assertEquals("name: ", s);
    } 
 
    public void testHeaderFormattingInvalidInput() throws Exception { 
        try { 
            BasicLineFormatter.formatHeader
                (null, BasicLineFormatter.DEFAULT);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
        try { 
            BasicLineFormatter.DEFAULT.formatHeader
                (new CharArrayBuffer(10), (Header) null);
            fail("IllegalArgumentException should habe been thrown");
        } catch (IllegalArgumentException ex) {
            // expected 
        } 
    } 
 
}