PawelAdamski / HttpClientMock

Library for mocking Apache HttpClient.
MIT License
44 stars 9 forks source link

Add support for URL-encoded form parameters #20

Closed mangstadt closed 4 years ago

mangstadt commented 4 years ago

These kinds of form parameters are typically found in the body of POST requests when a form is submitted on a website. Don't know if this would be useful to add or not.

Examples:

client.onPost("/login")
  .withFormParameter("username", "John")
  .withFormParameter("password", Matchers.any(String.class))
.doReturnStatus(200);
Map<String, Matcher<String>> parameters = new HashMap<>();
parameters.put("username", Matchers.equalTo("John"));
parameters.put("password", Matchers.any(String.class));
client.onPost("/login")
  .withBody(parameters)
.doReturnStatus(200);
client.onGet("/foo").doReturnFormParams(Arrays.asList(
  new BasicNameValuePair("one", "1"),
  new BasicNameValuePair("one", "2")
));
PawelAdamski commented 4 years ago

First of all thanks for the contribution. After the first review, your changes look good to me. Please give me some time to have a deeper look.

mangstadt commented 4 years ago

Of course, let me know if you have any questions. Thanks for looking at it.

Sorry that the commit of my previous pull request was included in this pull request. I'm not too familiar with how pull requests work!

mangstadt commented 4 years ago

Sure thing!