mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-05 00:22:48 +00:00
Merge pull request #418 from wengertj
* pr/418: Polish "Cleanup tests by using more idiomatic assertj assertions" Cleanup tests by using more idiomatic assertj assertions Closes gh-418
This commit is contained in:
commit
bebe9e50ed
3 changed files with 11 additions and 11 deletions
|
@ -53,7 +53,7 @@ public class ValidatorTests {
|
||||||
Set<ConstraintViolation<Person>> constraintViolations = validator
|
Set<ConstraintViolation<Person>> constraintViolations = validator
|
||||||
.validate(person);
|
.validate(person);
|
||||||
|
|
||||||
assertThat(constraintViolations.size()).isEqualTo(1);
|
assertThat(constraintViolations).hasSize(1);
|
||||||
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
|
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
|
||||||
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
|
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
|
||||||
assertThat(violation.getMessage()).isEqualTo("must not be empty");
|
assertThat(violation.getMessage()).isEqualTo("must not be empty");
|
||||||
|
|
|
@ -26,10 +26,10 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link PetTypeFormatter}
|
* Test class for {@link PetTypeFormatter}
|
||||||
|
@ -54,19 +54,19 @@ public class PetTypeFormatterTests {
|
||||||
PetType petType = new PetType();
|
PetType petType = new PetType();
|
||||||
petType.setName("Hamster");
|
petType.setName("Hamster");
|
||||||
String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH);
|
String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH);
|
||||||
assertEquals("Hamster", petTypeName);
|
assertThat(petTypeName).isEqualTo("Hamster");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldParse() throws ParseException {
|
public void shouldParse() throws ParseException {
|
||||||
Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes());
|
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
||||||
PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH);
|
PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH);
|
||||||
assertEquals("Bird", petType.getName());
|
assertThat(petType.getName()).isEqualTo("Bird");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ParseException.class)
|
@Test(expected = ParseException.class)
|
||||||
public void shouldThrowParseException() throws ParseException {
|
public void shouldThrowParseException() throws ParseException {
|
||||||
Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes());
|
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
||||||
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,17 +79,17 @@ public class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindOwnersByLastName() {
|
public void shouldFindOwnersByLastName() {
|
||||||
Collection<Owner> owners = this.owners.findByLastName("Davis");
|
Collection<Owner> owners = this.owners.findByLastName("Davis");
|
||||||
assertThat(owners.size()).isEqualTo(2);
|
assertThat(owners).hasSize(2);
|
||||||
|
|
||||||
owners = this.owners.findByLastName("Daviss");
|
owners = this.owners.findByLastName("Daviss");
|
||||||
assertThat(owners.isEmpty()).isTrue();
|
assertThat(owners).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindSingleOwnerWithPet() {
|
public void shouldFindSingleOwnerWithPet() {
|
||||||
Owner owner = this.owners.findById(1);
|
Owner owner = this.owners.findById(1);
|
||||||
assertThat(owner.getLastName()).startsWith("Franklin");
|
assertThat(owner.getLastName()).startsWith("Franklin");
|
||||||
assertThat(owner.getPets().size()).isEqualTo(1);
|
assertThat(owner.getPets()).hasSize(1);
|
||||||
assertThat(owner.getPets().get(0).getType()).isNotNull();
|
assertThat(owner.getPets().get(0).getType()).isNotNull();
|
||||||
assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
|
assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ public class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindVisitsByPetId() throws Exception {
|
public void shouldFindVisitsByPetId() throws Exception {
|
||||||
Collection<Visit> visits = this.visits.findByPetId(7);
|
Collection<Visit> visits = this.visits.findByPetId(7);
|
||||||
assertThat(visits.size()).isEqualTo(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();
|
assertThat(visitArr[0].getDate()).isNotNull();
|
||||||
assertThat(visitArr[0].getPetId()).isEqualTo(7);
|
assertThat(visitArr[0].getPetId()).isEqualTo(7);
|
||||||
|
|
Loading…
Reference in a new issue