diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/Test.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/Test.java new file mode 100644 index 0000000..dc8e59a --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/Test.java @@ -0,0 +1,4 @@ +package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception; + +public class Test { +} diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidAdressExceptionTest.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidAdressExceptionTest.java new file mode 100644 index 0000000..69fecc7 --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidAdressExceptionTest.java @@ -0,0 +1,67 @@ +package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid; + +import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidAdressException; +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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class NotValidAdressExceptionTest { + + @Test + @DisplayName("Exception should be created with the provided message") + void testExceptionCreation() { + String errorMessage = "Adresse is not valid"; + + NotValidAdressException exception = new NotValidAdressException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @ParameterizedTest + @ValueSource(strings = { + "rue is not valide", + "city is not valide", + "code postal is not valide", + "Country is not valide" + }) + @DisplayName("Exception should handle different validation messages") + void testExceptionWithDifferentMessages(String errorMessage) { + NotValidAdressException exception = new NotValidAdressException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be properly thrown and caught") + void testExceptionCanBeThrownAndCaught() { + String errorMessage = "Required field is missing"; + + Exception exception = assertThrows(NotValidAdressException.class, () -> { + throw new NotValidAdressException(errorMessage); + }); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be catchable as a general Exception") + void testExceptionInheritance() { + String errorMessage = "Invalid Adresse "; + + try { + throw new NotValidAdressException(errorMessage); + } catch (Exception e) { + assertEquals(NotValidAdressException.class, e.getClass()); + assertEquals(errorMessage, e.getMessage()); + } + } + + + + + +} diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidCommandeExceptionTest.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidCommandeExceptionTest.java new file mode 100644 index 0000000..04c2020 --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidCommandeExceptionTest.java @@ -0,0 +1,61 @@ +package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid; + +import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException; +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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class NotValidCommandeExceptionTest { + + @Test + @DisplayName("Exception should be created with the provided message") + void testExceptionCreation() { + String errorMessage = "Commande is not valid"; + + NotValidCommandeException exception = new NotValidCommandeException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @ParameterizedTest + @ValueSource(strings = { + "Mode Paiement is not valide", + "List ligne commande is not valide" + }) + @DisplayName("Exception should handle different validation messages") + void testExceptionWithDifferentMessages(String errorMessage) { + NotValidCommandeException exception = new NotValidCommandeException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be properly thrown and caught") + void testExceptionCanBeThrownAndCaught() { + String errorMessage = "Required field is missing"; + + Exception exception = assertThrows(NotValidCommandeException.class, () -> { + throw new NotValidCommandeException(errorMessage); + }); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be catchable as a general Exception") + void testExceptionInheritance() { + String errorMessage = "Invalid Commande "; + + try { + throw new NotValidCommandeException(errorMessage); + } catch (Exception e) { + assertEquals(NotValidCommandeException.class, e.getClass()); + assertEquals(errorMessage, e.getMessage()); + } + } + +} diff --git a/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidLigneCommandeExceptionTest.java b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidLigneCommandeExceptionTest.java new file mode 100644 index 0000000..11fab22 --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/commande/exception/valid/NotValidLigneCommandeExceptionTest.java @@ -0,0 +1,47 @@ +package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid; + +import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidLigneCommandeException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class NotValidLigneCommandeExceptionTest { + + @Test + @DisplayName("Exception should handle different validation messages") + void testExceptionCreation() { + String errorMessage = "Ligne commande is not valide"; + NotValidLigneCommandeException exception = new NotValidLigneCommandeException(errorMessage); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be properly thrown and caught") + void testExceptionCanBeThrownAndCaught() { + String errorMessage = "Required field is missing"; + + Exception exception = assertThrows(NotValidLigneCommandeException.class, () -> { + throw new NotValidLigneCommandeException(errorMessage); + }); + + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + @DisplayName("Exception should be catchable as a general Exception") + void testExceptionInheritance() { + String errorMessage = "Invalid Commande "; + + try { + throw new NotValidLigneCommandeException(errorMessage); + } catch (Exception e) { + assertEquals(NotValidLigneCommandeException.class, e.getClass()); + assertEquals(errorMessage, e.getMessage()); + } + } + + +}