forked from pierront/mylibrary-template
✅ oublie des test général pour booksalesinfo et bookdetails
This commit is contained in:
+36
-10
@@ -23,13 +23,39 @@ public class BookValidatorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should validate book with valid data")
|
||||
void testValidateValidCustomer() {
|
||||
void testValidateValidBook() {
|
||||
LocalDate date = LocalDate.of(2026, 3, 24);
|
||||
BookInfo validBook = new BookInfo("0000000000000","La vie de Maxime", "Marvin Aubert", "Kioon", date);
|
||||
|
||||
assertDoesNotThrow(() -> BookValidator.validate(validBook));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should validate book details with valid data")
|
||||
void testValidateValidBookDetails() {
|
||||
ArrayList<String> categories = new ArrayList<>();
|
||||
categories.add("Thriller");
|
||||
categories.add("Biographie");
|
||||
BookDetails validBookDetails = BookDetails.builder()
|
||||
.categories(categories)
|
||||
.description("C'était un brave partit trop tôt")
|
||||
.language("Français")
|
||||
.build();
|
||||
|
||||
assertDoesNotThrow(() -> BookValidator.validate(validBookDetails));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should validate book sales informations with valid data")
|
||||
void testValidateValidBookSalesInfo() {
|
||||
BookSalesInfo validBookSalesInfo = BookSalesInfo.builder()
|
||||
.price(15)
|
||||
.stock(10)
|
||||
.build();
|
||||
|
||||
assertDoesNotThrow(() -> BookValidator.validate(validBookSalesInfo));
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("ISBN validation tests")
|
||||
class ISBNValidationTests {
|
||||
@@ -45,12 +71,12 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithBlankTitle)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.ISBN_CANNOT_BE_BLANK, exception.getMessage());
|
||||
assertEquals(BookValidator.ISBN_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {" ", " ", "\t", "\n"})
|
||||
@DisplayName("Should throw exception when title contains only whitespace")
|
||||
@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);
|
||||
@@ -60,7 +86,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithWhitespaceTitle)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.TITLE_CANNOT_BE_BLANK, exception.getMessage());
|
||||
assertEquals(BookValidator.ISBN_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -75,7 +101,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithWhitespaceTitle)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.ISBN_CANNOT_CONTAIN_MORE_OR_LESS_THIRTEEN_CHARACTER, exception.getMessage());
|
||||
assertEquals(BookValidator.ISBN_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +222,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithFuturDate)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.DATE_CANNOT_BE_AFTER_TODAY, exception.getMessage());
|
||||
assertEquals(BookValidator.DATE_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +244,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithNegativePrice)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.PRICE_CANNOT_BE_NEGATIVE_OR_EQUAL_ZERO, exception.getMessage());
|
||||
assertEquals(BookValidator.PRICE_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +265,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithNegativeStock)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.STOCK_CANNOT_BE_NEGATIVE, exception.getMessage());
|
||||
assertEquals(BookValidator.STOCK_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +290,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithEmptyCategories)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.Categories_CANNOT_BE_EMPTY, exception.getMessage());
|
||||
assertEquals(BookValidator.CATEGORIES_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -284,7 +310,7 @@ public class BookValidatorTest {
|
||||
() -> BookValidator.validate(bookWithWhitespaceCategories)
|
||||
);
|
||||
|
||||
assertEquals(BookValidator.Categories_CANNOT_CONTAIN_BLANK, exception.getMessage());
|
||||
assertEquals(BookValidator.CATEGORIES_IS_NOT_VALID, exception.getMessage());
|
||||
}
|
||||
|
||||
static Stream<ArrayList<String>> provideLists() {
|
||||
|
||||
Reference in New Issue
Block a user