This project demonstrates the implementation of test-driven development (TDD) principles for a simple LibrarySystem using Java. The key focus is on three main methods: getBooksByAuthor
, getBooksByTitle
, and getBooksByAuthorAndTitle
.
- Book.java: Represents a book with
id
,title
, andauthor
. - BookService.java: Provides methods to retrieve books by author, title, or both.
- IBookRepository.java: Interface for book repository.
- BookRepository.java: Implementation of
IBookRepository
. - FakeRepositoryForTest.java: Mock repository for testing purposes.
- BookServiceTest.java: Contains test cases for
BookService
methods.
-
Test with an author that has books:
-
Test with an author that has no books:
-
Test with null or empty author string:
-
Test with an author that has multiple books:
-
Test with special characters in the author's name:
-
Test with a title that has books:
-
Test with a title that has no books:
-
Test with null or empty title string:
-
Test with a title that has multiple books:
-
Test with special characters in the title:
-
Test with a valid author and title combination:
-
Test with a valid author but invalid title:
-
Test with an invalid author but valid title:
-
Test with both invalid author and title:
-
Test with an author and title combination that appears multiple times:.
To run the tests, follow these steps:
-
Set Up JUnit 5 Dependency:
- Ensure JUnit 5 is added to your project dependencies (Maven or Gradle).
-
Run Tests in IntelliJ IDEA:
- Right-click on the
BookServiceTest
class and selectRun 'BookServiceTest'
.
- Right-click on the
-
Verify Test Results:
- Ensure all tests pass and verify the output for any failures.