Code Change Matcher

Use code matchers to validate that a block of code changes a value: Groovy code { updateDbEntity(dbEntity) } should change("dbEntity.id", dbEntity::getId) > expecting code to change value of dbEntity.id X failed expecting code to change value of dbEntity.id: actual: "id1" <java.lang.String> expected: not "id1" <java.lang.String> (0ms) Check matchers/import-and-dependencies Import And Dependencies for prerequisites. Java code(() -> { updateDbEntity(dbEntity); }).should(change("dbEntity.id", dbEntity::getId)); > expecting code to change value of dbEntity.id X failed expecting code to change value of dbEntity.id: actual: "id1" <java.lang.String> expected: not "id1" <java.lang.String> (0ms) Check matchers/import-and-dependencies Import And Dependencies for prerequisites. Pass a java bean to to validate that at least one property is changed Groovy code { buggyOperation(dbEntity) } should change("dbEntity", dbEntity) > expecting code to change value of dbEntity X failed expecting code to change value of dbEntity: dbEntity.description: actual: "description1" <java.lang.String> expected: not "description1" <java.lang.String> dbEntity.id: actual: "id1" <java.lang.String> expected: not "id1" <java.lang.String> dbEntity.value: actual: 100 <java.lang.Integer> expected: not 100 <java.lang.Integer> (1ms) Java code(() -> { buggyOperation(dbEntity); }).should(change("dbEntity", dbEntity)); > expecting code to change value of dbEntity X failed expecting code to change value of dbEntity: dbEntity.description: actual: "description1" <java.lang.String> expected: not "description1" <java.lang.String> dbEntity.id: actual: "id1" <java.lang.String> expected: not "id1" <java.lang.String> dbEntity.value: actual: 100 <java.lang.Integer> expected: not 100 <java.lang.Integer> (1ms) Use shouldNot to enforce that a value doesn't change Groovy code { calculatePrice(dbEntity) } shouldNot change("dbEntity", dbEntity) > expecting code to not change value of dbEntity X failed expecting code to not change value of dbEntity: dbEntity.description: actual: "description-changed" <java.lang.String> expected: "description1" <java.lang.String> ^ dbEntity.value: actual: 110 <java.lang.Integer> expected: 100 <java.lang.Integer> (1ms) Java code(() -> { calculatePrice(dbEntity); }).shouldNot(change("dbEntity", dbEntity)); > expecting code to not change value of dbEntity X failed expecting code to not change value of dbEntity: dbEntity.description: actual: "description-changed" <java.lang.String> expected: "description1" <java.lang.String> ^ dbEntity.value: actual: 110 <java.lang.Integer> expected: 100 <java.lang.Integer> (1ms)