Learn to distinguish a valid business response from an intentionally unusual HTTP status. These read-only examples do not require authentication.
The first test checks the status, content type and each drink type. The second expects the teapot endpoint to return HTTP 418.
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
class CoffeeApiTest {
@Test void hotDrinksHaveTheExpectedType() {
given().baseUri("https://funapi.dev/api")
.header("X-Sandbox-ID", UUID.randomUUID().toString())
.queryParam("type", "hot")
.when().get("/coffee/v1/drinks")
.then().statusCode(200).contentType("application/json")
.body("data.size()", greaterThan(0))
.body("data.type", everyItem(equalTo("hot")));
}
@Test void teapotStatusIsAnExpectedResult() {
given().baseUri("https://funapi.dev/api")
.header("X-Sandbox-ID", UUID.randomUUID().toString())
.when().get("/coffee/v1/teapot")
.then().statusCode(418);
}
}Add GET /coffee/v1/drinks?type=warm and expect 400. Keep this separate from the valid hot/cold cases so a failure explains which contract changed.
The provided two tests pass: hot drinks return JSON with 200, and the teapot returns 418. The optional invalid type returns 400.
Download this practice guide · Download the practice Postman collection
Last updated