Début de la feature avec des tests de base sur les variables #3

Open
Patrick FELIX-VIMALARATNAM wants to merge 19 commits from lebretonm/Projet_Pierront_Maxime_Marvin_Patrick:feature/RegisterNewBook into main
3 changed files with 60 additions and 0 deletions
Showing only changes of commit ee299e1e19 - Show all commits
@@ -0,0 +1,11 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
import java.text.MessageFormat;
public class BookNotFoundException extends RuntimeException {
public static final String THE_BOOK_WITH_ID_DOES_NOT_EXIST_MESSAGE = "The book with isbn {0} does not exist";
public BookNotFoundException(String isbn) {
super(MessageFormat.format(THE_BOOK_WITH_ID_DOES_NOT_EXIST_MESSAGE, isbn));
}
}
@@ -0,0 +1,48 @@
package fr.iut_fbleau.but3.dev62.mylibrary.book.exception;
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.assertTrue;
public class BookNotFoundExceptionTest {
@Test
@DisplayName("Exception message should contain the isbn provided")
void testExceptionMessageContainsIsbn() {
String isbn = "1234567891012";
BookNotFoundException exception = new BookNotFoundException(isbn);
String expectedMessage = String.format("The book with isbn %s does not exist", isbn);
assertEquals(expectedMessage, exception.getMessage());
}
@Test
@DisplayName("Exception should use the correct constant message format")
void testExceptionUsesConstantMessageFormat() {
String isbn = "1234567891012";
BookNotFoundException exception = new BookNotFoundException(isbn);
String expectedFormatWithPlaceholder = "The book with isbn {0} does not exist";
assertEquals(BookNotFoundException.THE_BOOK_WITH_ID_DOES_NOT_EXIST_MESSAGE,
expectedFormatWithPlaceholder);
assertTrue(exception.getMessage().contains(isbn.toString()));
}
@Test
@DisplayName("Exception should be properly thrown and caught")
void testExceptionCanBeThrownAndCaught() {
String isbn = "1234567891012";
try {
throw new BookNotFoundException(isbn);
} catch (BookNotFoundException e) {
String expectedMessage = String.format("The book with isbn %s does not exist", isbn);
assertEquals(expectedMessage, e.getMessage());
}
}
}
@@ -6,6 +6,7 @@ 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.entity.Book;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.BookNotFoundException;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.BookNotFoundExceptionTest;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.IllegalBookStockException;
import fr.iut_fbleau.but3.dev62.mylibrary.book.exception.NotValidBookException;
import fr.iut_fbleau.but3.dev62.mylibrary.book.repository.BookRepository;