mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Improved execution of grouped assertions
Signed-off-by: Elvys Soares <eas5@cin.ufpe.br>
This commit is contained in:
parent
e2fbc56130
commit
14070f0305
1 changed files with 21 additions and 14 deletions
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.samples.petclinic.service;
|
package org.springframework.samples.petclinic.service;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -93,10 +94,12 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
void shouldFindSingleOwnerWithPet() {
|
void shouldFindSingleOwnerWithPet() {
|
||||||
Owner owner = this.owners.findById(1);
|
Owner owner = this.owners.findById(1);
|
||||||
assertThat(owner.getLastName()).startsWith("Franklin");
|
assertAll(
|
||||||
assertThat(owner.getPets()).hasSize(1);
|
() -> assertThat(owner.getLastName()).startsWith("Franklin"),
|
||||||
assertThat(owner.getPets().get(0).getType()).isNotNull();
|
() -> assertThat(owner.getPets()).hasSize(1),
|
||||||
assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
|
() -> assertThat(owner.getPets().get(0).getType()).isNotNull(),
|
||||||
|
() -> assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -136,9 +139,10 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
void shouldFindPetWithCorrectId() {
|
void shouldFindPetWithCorrectId() {
|
||||||
Pet pet7 = this.pets.findById(7);
|
Pet pet7 = this.pets.findById(7);
|
||||||
assertThat(pet7.getName()).startsWith("Samantha");
|
assertAll(
|
||||||
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
|
() -> assertThat(pet7.getName()).startsWith("Samantha"),
|
||||||
|
() -> assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -191,12 +195,13 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
void shouldFindVets() {
|
void shouldFindVets() {
|
||||||
Collection<Vet> vets = this.vets.findAll();
|
Collection<Vet> vets = this.vets.findAll();
|
||||||
|
|
||||||
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
||||||
assertThat(vet.getLastName()).isEqualTo("Douglas");
|
assertAll(
|
||||||
assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
|
() -> assertThat(vet.getLastName()).isEqualTo("Douglas"),
|
||||||
assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
|
() -> assertThat(vet.getNrOfSpecialties()).isEqualTo(2),
|
||||||
assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
|
() -> assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry"),
|
||||||
|
() -> assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -220,8 +225,10 @@ class ClinicServiceTests {
|
||||||
Collection<Visit> visits = this.visits.findByPetId(7);
|
Collection<Visit> visits = this.visits.findByPetId(7);
|
||||||
assertThat(visits).hasSize(2);
|
assertThat(visits).hasSize(2);
|
||||||
Visit[] visitArr = visits.toArray(new Visit[visits.size()]);
|
Visit[] visitArr = visits.toArray(new Visit[visits.size()]);
|
||||||
assertThat(visitArr[0].getDate()).isNotNull();
|
assertAll(
|
||||||
assertThat(visitArr[0].getPetId()).isEqualTo(7);
|
() -> assertThat(visitArr[0].getDate()).isNotNull(),
|
||||||
|
() -> assertThat(visitArr[0].getPetId()).isEqualTo(7)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue