From 2b57c51d41153b99a2d0b8880e65c845e72dd60e Mon Sep 17 00:00:00 2001 From: Abhijay Kumar Date: Fri, 21 Aug 2020 19:43:53 +0530 Subject: [PATCH] Simlified assertions using better asset methods Chained AssertJ assertions should be simplified to the corresponding dedicated assertion [RSPEC-5838](https://rules.sonarsource.com/java/RSPEC-5838) --- .../samples/petclinic/model/ValidatorTests.java | 2 +- .../samples/petclinic/service/ClinicServiceTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java index 8d754900d..9c4afa562 100644 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java @@ -53,7 +53,7 @@ class ValidatorTests { assertThat(constraintViolations).hasSize(1); ConstraintViolation violation = constraintViolations.iterator().next(); - assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); + assertThat(violation.getPropertyPath()).hasToString("firstName"); assertThat(violation.getMessage()).isEqualTo("must not be empty"); } diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java index a7f3d9d24..169d5511b 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java @@ -112,10 +112,10 @@ class ClinicServiceTests { owner.setCity("Wollongong"); owner.setTelephone("4444444444"); this.owners.save(owner); - assertThat(owner.getId().longValue()).isNotEqualTo(0); + assertThat(owner.getId().longValue()).isNotZero(); owners = this.owners.findByLastName("Schultz"); - assertThat(owners.size()).isEqualTo(found + 1); + assertThat(owners).hasSize(found + 1); } @Test