How it works...

This recipe showed two methods that can be used to test assertions. The assertExpectedLines method is the typical method you should use, but you can also use the assertCount method where appropriate.

When using assertExpectedLines, it expects an AtlSpecification to act as the criteria. The plain-English request we are making here is this: for a list of vehicle groups, assert that there should be a vehicle group with the ID of groupId.

Due to the fluent coding style, we could write all of this on one line. This is normally preferable. In this example, a var was declared for the query class in order to demonstrate a way to interact with the query class without a specification class.

In order to use the assertCount method, the query needs to be told the criterion before the assert is called. This is done using fluent with methods. We only have one criterion, but we could have several.

If we created a vehicle group with an ID of VG1 and a name of VG Name, we might want to test that the vehicle group was created with the correct ID and name. In this case, we would write the following code instead:

groups.withVehicleGroupId('VG1').withName('VG Name').assertCount(1, 'Expected 1 record');