test: refactor using AssertJ assertions

This commit is contained in:
Anyul Rivas 2024-03-17 15:49:06 +01:00 committed by Dave Syer
parent c5b3b3597e
commit 7055f0c6a6
2 changed files with 6 additions and 6 deletions

View file

@ -231,8 +231,8 @@ class OwnerControllerTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Pet> pets = (List<Pet>) item; List<Pet> pets = (List<Pet>) item;
Pet pet = pets.get(0); Pet pet = pets.get(0);
return !pet.getVisits().isEmpty(); return !pet.getVisits().isEmpty();
} }
@Override @Override
public void describeTo(Description description) { public void describeTo(Description description) {

View file

@ -17,6 +17,7 @@
package org.springframework.samples.petclinic.system; package org.springframework.samples.petclinic.system;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -35,10 +36,9 @@ class CrashControllerTests {
@Test @Test
void testTriggerException() { void testTriggerException() {
RuntimeException thrown = assertThrows(RuntimeException.class, () -> testee.triggerException()); assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(()->testee.triggerException())
assertThat(thrown.getMessage()) .withMessageContaining("Expected: controller used to showcase what happens when an exception is thrown");
.isEqualTo("Expected: controller used to showcase what happens when an exception is thrown");
} }
} }