jerryh91
jerryh91

Reputation: 1795

Java Spring: JUnit Hamcrest: Expecting Collection

i'm running my integration test suite in my Java Spring Web application, however running into the following error.

There is a single item value: {id value} for id, returned in the response.

java.lang.AssrtionError: 1 expectation failed.
JSON path data.id doesn't match.
Expected: a collection containing "BUNDLE_A"
Actual: BUNDLE_A

IntegrationTest.java:

 @Test
  public void testBundle() throws Exception {
    RestAssured.when()
      .get("v1/bundles/{bundleId}", TEST_BUNDLE_ID)
    .then()
      .statusCode(HttpStatus.OK.value())
      .body("data.id", hasItem(TEST_BUNDLE_ID))
      .body("errorCode", nullValue());
  }

Upvotes: 1

Views: 343

Answers (1)

Cortwave
Cortwave

Reputation: 4907

Replace your hasItem with equalTo:

 @Test
  public void testBundle() throws Exception {
    RestAssured.when()
      .get("v1/bundles/{bundleId}", TEST_BUNDLE_ID)
    .then()
      .statusCode(HttpStatus.OK.value())
      .body("data.id", equalTo(TEST_BUNDLE_ID))
      .body("errorCode", nullValue());
  }

Upvotes: 1

Related Questions