Skip to content

Commit 03b1e60

Browse files
committed
Test invalid post IDs
1 parent 7662fa6 commit 03b1e60

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/test/java/com/typicode/jsonplaceholder/features/Posts.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ Feature: Posts Endpoint
3939
"""
4040
And the "userId" field in the response body has a value of 1
4141

42+
Scenario Outline: Get post with invalid ID - post #<ID>
43+
When I make a GET request to the Posts endpoint with a path parameter of <ID>
44+
Then the response has a status code of 404
45+
And the response body is an empty JSON object
46+
Examples:
47+
| ID |
48+
| 0 |
49+
| 101 |
50+
| -1 |

src/test/java/com/typicode/jsonplaceholder/steps/CommonSteps.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void makeGetRequest(String endpoint) {
5757
response = RequestHelpers.sendGetRequestTo(endpoints.get(endpoint));
5858
responses.add(response);
5959
}
60-
@When("^I make a GET request to the (Posts|Comments|Albums|Photos|ToDos|Users) endpoint with a path parameter of (\\d+)$")
60+
@When("^I make a GET request to the (Posts|Comments|Albums|Photos|ToDos|Users) endpoint with a path parameter of (-?\\d+)$")
6161
public static void makeGetRequestWithPathParameter(String endpoint, int pathParam) {
6262
response = RequestHelpers.sendGetRequestTo(endpoints.get(endpoint) + "/" + pathParam);
6363
responses.add(response);
@@ -110,5 +110,10 @@ public static void verifyResponseBodyAgainstDataTable(DataTable dataTable) {
110110
expectedBody.forEach((k,v) -> assertEquals(expectedBody.get(k), actual.get(k).toString()));
111111
}
112112

113+
@Then("the response body is an empty JSON object")
114+
public static void verifyResponseBodyIsEmptyJSONObject() {
115+
assertEquals(new JSONObject().toString(), response.body());
116+
}
117+
113118

114119
}

0 commit comments

Comments
 (0)