Polish test with BDDMockito and Assertj assertions

This commit is contained in:
Antoine Rey
2019-10-30 19:42:15 +01:00
parent 101abcaac1
commit 412d90b2a1
3 changed files with 9 additions and 9 deletions

View File

@@ -32,7 +32,7 @@ class ValidatorTests {
val validator = createValidator()
val constraintViolations = validator.validate(person)
assertThat(constraintViolations.size).isEqualTo(1)
assertThat(constraintViolations).hasSize(1)
val violation = constraintViolations.iterator().next()
assertThat(violation.propertyPath.toString()).isEqualTo("firstName")
assertThat(violation.message).isEqualTo("must not be empty")

View File

@@ -193,8 +193,8 @@ class OwnerControllerTest {
@Suppress("UNCHECKED_CAST")
override fun matches(item: Any?): Boolean {
val pets : List<Pet> = item as List<Pet>
val pet = pets.get(0)
val pets : Set<Pet> = item as Set<Pet>
val pet = pets.iterator().next()
return !pet.getVisits().isEmpty()
} })))
.andExpect(view().name("owners/ownerDetails"))

View File

@@ -1,13 +1,13 @@
package org.springframework.samples.petclinic.owner
import org.junit.jupiter.api.Assertions.assertEquals
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.BDDMockito.given
import org.springframework.test.context.junit.jupiter.SpringExtension
import java.text.ParseException
import java.util.*
@@ -35,21 +35,21 @@ class PetTypeFormatterTest {
val petType = PetType()
petType.name = "Hamster"
val petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH)
assertEquals("Hamster", petTypeName)
assertThat("Hamster").isEqualTo(petTypeName)
}
@Test
@Throws(ParseException::class)
fun shouldParse() {
Mockito.`when`(this.pets.findPetTypes()).thenReturn(makePetTypes())
given(this.pets.findPetTypes()).willReturn(makePetTypes())
val petType = petTypeFormatter.parse("Bird", Locale.ENGLISH)
assertEquals("Bird", petType.name)
assertThat("Bird").isEqualTo(petType.name)
}
@Test
@Throws(ParseException::class)
fun shouldThrowParseException() {
Mockito.`when`(this.pets.findPetTypes()).thenReturn(makePetTypes())
given(this.pets.findPetTypes()).willReturn(makePetTypes())
assertThrows(ParseException::class.java, { petTypeFormatter.parse("Fish", Locale.ENGLISH) })
}