Skip to content

Commit

Permalink
Merge pull request spring-projects#418 from wengertj
Browse files Browse the repository at this point in the history
* pr/418:
  Polish "Cleanup tests by using more idiomatic assertj assertions"
  Cleanup tests by using more idiomatic assertj assertions

Closes spring-projectsgh-418
  • Loading branch information
snicoll committed Jun 1, 2019
2 parents 6e24f5d + 8919c73 commit bebe9e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void shouldNotValidateWhenFirstNameEmpty() {
Set<ConstraintViolation<Person>> constraintViolations = validator
.validate(person);

assertThat(constraintViolations.size()).isEqualTo(1);
assertThat(constraintViolations).hasSize(1);
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
assertThat(violation.getMessage()).isEqualTo("must not be empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
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}
Expand All @@ -54,19 +54,19 @@ public void testPrint() {
PetType petType = new PetType();
petType.setName("Hamster");
String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH);
assertEquals("Hamster", petTypeName);
assertThat(petTypeName).isEqualTo("Hamster");
}

@Test
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);
assertEquals("Bird", petType.getName());
assertThat(petType.getName()).isEqualTo("Bird");
}

@Test(expected = ParseException.class)
public void shouldThrowParseException() throws ParseException {
Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes());
given(this.pets.findPetTypes()).willReturn(makePetTypes());
petTypeFormatter.parse("Fish", Locale.ENGLISH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ public class ClinicServiceTests {
@Test
public void shouldFindOwnersByLastName() {
Collection<Owner> owners = this.owners.findByLastName("Davis");
assertThat(owners.size()).isEqualTo(2);
assertThat(owners).hasSize(2);

owners = this.owners.findByLastName("Daviss");
assertThat(owners.isEmpty()).isTrue();
assertThat(owners).isEmpty();
}

@Test
public void shouldFindSingleOwnerWithPet() {
Owner owner = this.owners.findById(1);
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().getName()).isEqualTo("cat");
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public void shouldAddNewVisitForPet() {
@Test
public void shouldFindVisitsByPetId() throws Exception {
Collection<Visit> visits = this.visits.findByPetId(7);
assertThat(visits.size()).isEqualTo(2);
assertThat(visits).hasSize(2);
Visit[] visitArr = visits.toArray(new Visit[visits.size()]);
assertThat(visitArr[0].getDate()).isNotNull();
assertThat(visitArr[0].getPetId()).isEqualTo(7);
Expand Down

0 comments on commit bebe9e5

Please sign in to comment.