Search code examples
assertassertionkatalon-studioassertj

org.assertj.core.api.Assertions doesNotContain array error


I wanted to use doesNotContain to make sure the response does not contains the string. but hitting error.

What should be the correct parameter to use?

test script:

import static org.assertj.core.api.Assertions.*

def testjson= new JsonSlurper().parseText(new String(response.responseText))
println('response text: \n' + JsonOutput.prettyPrint(JsonOutput.toJson(testjson)))


assert (testjson.testLines.lineId.contains("test123"))

assert (testjson.testLines.lineId.doesNotContain("test456"))

error

Reason:
groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.doesNotContain() is applicable for argument types: (java.lang.String) values: [test456]

sample response:

{
    "testId": "default",
    "createdDate": "2020-05-11T01:51:32.986Z",
    "lastUpdatedDate": "2020-05-11T01:51:32.986Z",
    "testLines": [
        {
            "lineId": "test123",
            "itemId": "test/test123"
        },
        {
            "lineId": "test999",
            "itemId": "test/test999"
        }
    ]
}

Solution

  • The compiler is complaining that doesNotContain() method expects some other input. I don't know about that method, but if the contains() method is working you can just negate the outcome of that one, using "!" in front of a logical statement:

    assert (!testjson.testLines.lineId.contains("test123"))