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

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