From c11f549e83cbbe4c390acab5f47137907b13bcf0 Mon Sep 17 00:00:00 2001 From: ducreux Date: Sat, 25 Apr 2026 12:39:19 +0200 Subject: [PATCH] validtest --- .../exception/NotValidAvisExceptionTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/exception/NotValidAvisExceptionTest.java diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/exception/NotValidAvisExceptionTest.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/exception/NotValidAvisExceptionTest.java new file mode 100644 index 0000000..066dbe1 --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/avis/exception/NotValidAvisExceptionTest.java @@ -0,0 +1,61 @@ +package fr.iut_fbleau.but3.dev62.mylibrary.avis.exception; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.*; + +class NotValidAvisExceptionTest { + + @Test + @DisplayName("Exception should be created with the provided message") + void testExceptionCreation() { + String errorMessage = "Note must be between 1 and 5"; + + NotValidAvisException exception = new NotValidAvisException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @ParameterizedTest + @ValueSource(strings = { + "Note must be between 1 and 5", + "Commentaire cannot be blank", + "Client id cannot be null", + "Livre id cannot be null", + "Date achat cannot be null" + }) + @DisplayName("Exception should handle different validation messages") + void testExceptionWithDifferentMessages(String errorMessage) { + NotValidAvisException exception = new NotValidAvisException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be properly thrown and caught") + void testExceptionCanBeThrownAndCaught() { + String errorMessage = "Note must be between 1 and 5"; + + Exception exception = assertThrows(NotValidAvisException.class, () -> { + throw new NotValidAvisException(errorMessage); + }); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be catchable as a general Exception") + void testExceptionInheritance() { + String errorMessage = "Commentaire cannot be blank"; + + try { + throw new NotValidAvisException(errorMessage); + } catch (Exception e) { + assertEquals(NotValidAvisException.class, e.getClass()); + assertEquals(errorMessage, e.getMessage()); + } + } +} \ No newline at end of file