A pre-built Java project for practising unit testing with JUnit 5 and AssertJ.
The source code is already implemented. Your job is to write the tests.
- Open this folder in IntelliJ IDEA as a Maven project.
- Wait for dependencies to download.
- Navigate to
src/test/java— you will find test class skeletons with TODO comments. - Write the tests described in each file.
- Run tests with the green arrow or
mvn test.
src/main/java/lv/bootcamp/shelter/
├── model/ → Animal, AnimalType (shared domain classes)
├── task1/ → AgeCalculator (pure logic)
├── task23/ → AnimalValidator (parameterized + exceptions)
├── task4/ → AnimalSorter (collection sorting)
├── task5/ → AnimalCsvParser (file I/O and nested tests)
├── task6/ → IntakeService, AnimalRepository (mocking a dependency)
└── stretch/ → AnimalReportWriter (stretch goal)
src/main/resources/
└── intake.csv → Sample data for CSV parsing tasks
src/test/java/lv/bootcamp/shelter/
├── task1/ → AgeCalculatorTest
├── task23/ → AnimalValidatorTest
├── task4/ → AnimalSorterTest
├── task5/ → AnimalCsvParserTest
├── task6/ → IntakeServiceTest (mocking with Mockito)
└── stretch/ → AnimalReportWriterTest (stretch)
| # | Package | Focus | Testing concepts |
|---|---|---|---|
| 1 | task1 |
Pure logic | assertEquals, AAA pattern, naming |
| 2 | task23 |
Multiple rules | @ParameterizedTest, @CsvSource |
| 3 | task23 |
Error cases | assertThrows, exception messages |
| 4 | task4 |
Collection order | AssertJ list assertions |
| 5 | task5 |
CSV scenarios | @Nested classes, @DisplayName |
| 6 | stretch |
File output formatting | AssertJ string/list assertions |
| 7 | task6 |
Mocking a dependency | @Mock, @InjectMocks, when/thenReturn, verify |
| 8 | All | Coverage | IntelliJ coverage runner |
task5 introduces Mockito basics: mock a repository dependency so you can test the IntakeService in isolation. JPA and controller tests come later in M14.
After completing tasks 1–7:
- Right-click the
testfolder → Run All Tests with Coverage - Review which lines are green (covered) vs red (not covered)
- Identify at least two untested branches
- Decide: would tests for those branches catch real bugs?
- Java 21
- JUnit Jupiter 5.11
- AssertJ 3.26
- Mockito 5.14 (used in
task5for mocking a dependency)