Created
April 7, 2012 16:23
-
-
Save hertzsprung/2330108 to your computer and use it in GitHub Desktop.
Combining Hamcrest matchers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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