réussite des test du validator

This commit is contained in:
2026-04-26 17:00:16 +02:00
parent 182fcc0259
commit 7d11743c02
3 changed files with 126 additions and 7 deletions
@@ -3,6 +3,7 @@ package fr.iut_fbleau.but3.dev62.mylibrary.book.validator;
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDetails;
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookInfo;
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookSalesInfo;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.NotValidBookException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@@ -62,13 +63,13 @@ public class BookValidatorTest {
@Test
@DisplayName("Should throw exception when isbn is blank")
void testValidateBlankTitle() {
void testValidateBlankISBN() {
LocalDate date = LocalDate.of(2026, 3, 24);
BookInfo bookWithBlankTitle = new BookInfo("", "La vie de Maxime", "Marvin Aubert", "Kioon", date);
BookInfo bookWithBlankISBN = new BookInfo("", "La vie de Maxime", "Marvin Aubert", "Kioon", date);
NotValidBookException exception = assertThrows(
NotValidBookException.class,
() -> BookValidator.validate(bookWithBlankTitle)
() -> BookValidator.validate(bookWithBlankISBN)
);
assertEquals(BookValidator.ISBN_IS_NOT_VALID, exception.getMessage());
@@ -79,11 +80,11 @@ public class BookValidatorTest {
@DisplayName("Should throw exception when isbn contains only whitespace")
void testValidateWhitespaceISBN(String whitespace) {
LocalDate date = LocalDate.of(2026, 3, 24);
BookInfo bookWithWhitespaceTitle = new BookInfo(whitespace, "La vie de Maxime", "Marvin Aubert", "Kioon", date);
BookInfo bookWithWhitespaceISBN = new BookInfo(whitespace, "La vie de Maxime", "Marvin Aubert", "Kioon", date);
NotValidBookException exception = assertThrows(
NotValidBookException.class,
() -> BookValidator.validate(bookWithWhitespaceTitle)
() -> BookValidator.validate(bookWithWhitespaceISBN)
);
assertEquals(BookValidator.ISBN_IS_NOT_VALID, exception.getMessage());
@@ -94,11 +95,11 @@ public class BookValidatorTest {
@DisplayName("Should throw exception when isbn contains only thriteen character")
void testValidateThirteenCharacterISBN(String number) {
LocalDate date = LocalDate.of(2026, 3, 24);
BookInfo bookWithWhitespaceTitle = new BookInfo(number, "La vie de Maxime", "Marvin Aubert", "Kioon", date);
BookInfo bookWithNotExactCharacterISBN = new BookInfo(number, "La vie de Maxime", "Marvin Aubert", "Kioon", date);
NotValidBookException exception = assertThrows(
NotValidBookException.class,
() -> BookValidator.validate(bookWithWhitespaceTitle)
() -> BookValidator.validate(bookWithNotExactCharacterISBN)
);
assertEquals(BookValidator.ISBN_IS_NOT_VALID, exception.getMessage());