test: rewrite assertion using AssertJ for consistency

This commit is contained in:
Anyul Rivas 2024-03-14 09:18:19 +01:00
parent a108f6c21b
commit 6a3d4aab57

View file

@ -16,7 +16,7 @@
package org.springframework.samples.petclinic.system; package org.springframework.samples.petclinic.system;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
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;
@ -34,13 +34,11 @@ class CrashControllerTests {
CrashController testee = new CrashController(); CrashController testee = new CrashController();
@Test @Test
void testTriggerException() throws Exception { void testTriggerException() {
RuntimeException thrown = assertThrows(RuntimeException.class, () -> { RuntimeException thrown = assertThrows(RuntimeException.class, () -> testee.triggerException());
testee.triggerException();
});
assertEquals("Expected: controller used to showcase what happens when an exception is thrown", assertThat(thrown.getMessage())
thrown.getMessage()); .isEqualTo("Expected: controller used to showcase what happens when an exception is thrown");
} }
} }