square / assertj-android

A set of AssertJ helpers geared toward testing Android.
https://square.github.io/assertj-android/
Apache License 2.0
1.58k stars 156 forks source link

Add query parameter and authority assertions to UriAssert #194

Closed iainmcgin closed 6 years ago

iainmcgin commented 8 years ago

There's some fancy footwork in this CL to allow fluent assertions about parameter values; I don't know if there is precedent for this elsewhere, or if it is frowned upon. For example, with this patch you can write:

assertThat(uri)
    .hasQueryParameter("user").withValue("bob@example.com")
    .hasQueryParameter("married")
    .hasQueryParameter("pets").withValues("Spot", "Daisy");

Whereas more conventionally I think you would have to write:

assertThat(uri).hasQueryParameter("user");
assertThat(uri.getQueryParameter("user")).isEqualTo("bob@example.com");
assertThat(uri.getQueryParameters("pets")).contains("Spot", "Daisy");

If you don't think the "withValue" extra fluent method is valuable, I can take that out, but personally I prefer it.

f2prateek commented 8 years ago

Why not keep it simple — assertThat(uri).hasQueryParameter("user", "bob@example.com")?