mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-17 15:35:20 +00:00
HTTPCLIENT-1494: null check in StringBody constructor
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1585944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7b9408e75f
commit
cb983ea5b0
@ -152,6 +152,7 @@ public StringBody(final String text) throws UnsupportedEncodingException {
|
|||||||
*/
|
*/
|
||||||
public StringBody(final String text, final ContentType contentType) {
|
public StringBody(final String text, final ContentType contentType) {
|
||||||
super(contentType);
|
super(contentType);
|
||||||
|
Args.notNull(text, "Text");
|
||||||
final Charset charset = contentType.getCharset();
|
final Charset charset = contentType.getCharset();
|
||||||
this.content = text.getBytes(charset != null ? charset : Consts.ASCII);
|
this.content = text.getBytes(charset != null ? charset : Consts.ASCII);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,16 @@ public void testStringBody() throws Exception {
|
|||||||
Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
|
Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
public void testStringBodyInvalidConstruction1() throws Exception {
|
||||||
|
new StringBody(null, ContentType.DEFAULT_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
public void testStringBodyInvalidConstruction2() throws Exception {
|
||||||
|
new StringBody("stuff", (ContentType) null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInputStreamBody() throws Exception {
|
public void testInputStreamBody() throws Exception {
|
||||||
final byte[] stuff = "Stuff".getBytes(Consts.ASCII);
|
final byte[] stuff = "Stuff".getBytes(Consts.ASCII);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user