Skip to content

Instantly share code, notes, and snippets.

@hertzsprung
Created April 7, 2012 16:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hertzsprung/2330108 to your computer and use it in GitHub Desktop.
Save hertzsprung/2330108 to your computer and use it in GitHub Desktop.
Combining Hamcrest matchers
package uk.co.datumedge.blog.hamcrest;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThan;
import javax.ws.rs.core.Response;
import org.hamcrest.Matchers;
import org.junit.Test;
public class ResponseMatchers {
@Test
public void assert4xxClassStatusAndEntity() {
Object expectedEntity = "expectedEntity";
Object actualEntity = "actualEntity";
Response response = Response.ok().entity(actualEntity).build();
assertThat(response, both(
Matchers.<Response>hasProperty("status", both(greaterThanOrEqualTo(400)).and(lessThan(500)))).and(
Matchers.<Response>hasProperty("entity", equalTo(expectedEntity))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment