From 33fcdcee0c5c87279cd89a118551a8cf5588ea83 Mon Sep 17 00:00:00 2001 From: ducreux Date: Sat, 25 Apr 2026 12:10:27 +0200 Subject: [PATCH] suite --- .../entity/AvisNotFoundExceptionTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/entity/AvisNotFoundExceptionTest.java diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/entity/AvisNotFoundExceptionTest.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/entity/AvisNotFoundExceptionTest.java new file mode 100644 index 0000000..fd7cc94 --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/entity/AvisNotFoundExceptionTest.java @@ -0,0 +1,46 @@ +package fr.iut_fbleau.but3.dev62.mylibrary.avis.exception; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +class AvisNotFoundExceptionTest { + + @Test + @DisplayName("Exception message should contain the UUID provided") + void testExceptionMessageContainsUUID() { + UUID uuid = UUID.randomUUID(); + + AvisNotFoundException exception = new AvisNotFoundException(uuid); + + String expectedMessage = String.format("The avis with id %s does not exist", uuid); + assertEquals(expectedMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should use the correct constant message format") + void testExceptionUsesConstantMessageFormat() { + UUID uuid = UUID.randomUUID(); + + AvisNotFoundException exception = new AvisNotFoundException(uuid); + + assertEquals("The avis with id {0} does not exist", + AvisNotFoundException.THE_AVIS_WITH_ID_DOES_NOT_EXIST_MESSAGE); + assertTrue(exception.getMessage().contains(uuid.toString())); + } + + @Test + @DisplayName("Exception should be properly thrown and caught") + void testExceptionCanBeThrownAndCaught() { + UUID uuid = UUID.randomUUID(); + + try { + throw new AvisNotFoundException(uuid); + } catch (AvisNotFoundException e) { + assertTrue(e.getMessage().contains(uuid.toString())); + } + } +} \ No newline at end of file