Feature/create subscription #3

Merged
Marvin AUBERT merged 11 commits from feature/create_subscription into main 2026-06-14 17:42:17 +02:00
2 changed files with 118 additions and 0 deletions
Showing only changes of commit 9e69e02066 - Show all commits
@@ -0,0 +1,58 @@
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class NotValidPaymentMethodEsceptionTest {
@Test
@DisplayName("Exception should be created with the provided message")
void testExceptionCreation() {
String errorMessage = "PaymentMethod data is not valid";
NotValidPaymentMethodException exception = new NotValidPaymentMethodException(errorMessage);
assertEquals(errorMessage, exception.getMessage());
}
@ParameterizedTest
@ValueSource(strings = {
"paymentType is not valid"
})
@DisplayName("Exception should handle different validation messages")
void testExceptionWithDifferentMessages(String errorMessage) {
NotValidPaymentMethodException exception = new NotValidPaymentMethodException(errorMessage);
assertEquals(errorMessage, exception.getMessage());
}
@Test
@DisplayName("Exception should be properly thrown and caught")
void testExceptionCanBeThrownAndCaught() {
String errorMessage = "paymentType is not valid";
Exception exception = assertThrows(NotValidPaymentMethodException.class, () -> {
throw new NotValidPaymentMethodException(errorMessage);
});
assertEquals(errorMessage, exception.getMessage());
}
@Test
@DisplayName("Exception should be catchable as a general Exception")
void testExceptionInheritance() {
String errorMessage = "Invalid paymentMethod data";
try {
throw new NotValidPaymentMethodException(errorMessage);
} catch (Exception e) {
assertEquals(NotValidPaymentMethodException.class, e.getClass());
assertEquals(errorMessage, e.getMessage());
}
}
}
@@ -0,0 +1,60 @@
package fr.iut_fbleau.but3.dev62.mylibrary.subscription.exception;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.exception.NotValidCustomerException;
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 NotValidSubscriptionExceptionTest {
@Test
@DisplayName("Exception should be created with the provided message")
void testExceptionCreation() {
String errorMessage = "Subscription data is not valid";
NotValidSubscriptionException exception = new NotValidSubscriptionException(errorMessage);
assertEquals(errorMessage, exception.getMessage());
}
@ParameterizedTest
@ValueSource(strings = {
"subscriptionDurationDesired will be 3, 6 or 12 by the ENUM file SubscriptionDurationDesired",
"desiredStartDate cannot be before today"
})
@DisplayName("Exception should handle different validation messages")
void testExceptionWithDifferentMessages(String errorMessage) {
NotValidSubscriptionException exception = new NotValidSubscriptionException(errorMessage);
assertEquals(errorMessage, exception.getMessage());
}
@Test
@DisplayName("Exception should be properly thrown and caught")
void testExceptionCanBeThrownAndCaught() {
String errorMessage = "desiredStartDate cannot be before today";
Exception exception = assertThrows(NotValidSubscriptionException.class, () -> {
throw new NotValidSubscriptionException(errorMessage);
});
assertEquals(errorMessage, exception.getMessage());
}
@Test
@DisplayName("Exception should be catchable as a general Exception")
void testExceptionInheritance() {
String errorMessage = "Invalid subscription data";
try {
throw new NotValidSubscriptionException(errorMessage);
} catch (Exception e) {
assertEquals(NotValidSubscriptionException.class, e.getClass());
assertEquals(errorMessage, e.getMessage());
}
}
}