La création d'un UrlEncodedFormEntity à partir d'une Liste de NameValuePairs lève une exception NullPointerException

Je suis de la création d'une unité de test pour essayer la servlet je viens de créer.

@Test
public void test() throws ParseException, IOException {

  HttpClient client = new DefaultHttpClient();
  HttpPost post = new HttpPost("http://localhost:8080/WebService/MakeBaby");

  List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

  nameValuePairs.add(new BasicNameValuePair("father_name", "Foo"));
  nameValuePairs.add(new BasicNameValuePair("mother_name", "Bar"));

  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  HttpResponse response = null;

  try {
    response = client.execute(post);
  } catch (ClientProtocolException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }

  String stringifiedResponse = EntityUtils.toString(response.getEntity());

  System.out.println(stringifiedResponse);

  assertNotNull(stringifiedResponse);
}

La ligne suivante génère une exception NullPointerException:

post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

Est-il quelque chose que je suis absent?

InformationsquelleAutor Kevin D. | 2012-06-08