mirror of
https://github.com/jlengrand/spring-petclinic-kotlin.git
synced 2026-03-10 08:41:20 +00:00
Polish test with BDDMockito and Assertj assertions
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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) })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user