Skip to content

London | 26-Java-June | Andrei Filippov | Sprint 5 | Backlog - #81

Open
Droid-An wants to merge 7 commits into
CodeYourFuture:mainfrom
Droid-An:sprint-5/backlog
Open

Droid-An wants to merge 7 commits into
CodeYourFuture:mainfrom
Droid-An:sprint-5/backlog

Conversation

@Droid-An

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

In this PR I added tests and logging to the service we wrote in sprint 4 backlog. Only the last 2 commit from 11 September matters, everything else is just a rebase.
I haven't wrote tests for ThreeYearsGenerator because they would be the same, and also I think oneYearGenerator and ThreeYearsGenerator should be one function, since they are sharing the same functionality

Questions

Instead of generating a mock list of rentals and verifying against that, I just checked some properties of the list. Is it alright?

@Droid-An Droid-An added 📅 Sprint 5 Assigned during Sprint 5 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Sep 15, 2026
@lukedsouza99
lukedsouza99 self-requested a review October 9, 2026 16:18
@lukedsouza99 lukedsouza99 self-assigned this Oct 9, 2026
this.rentals = threeYearContractRentalGenerator.generateRentals(contract);
} else {
throw new InvalidParameterException("Contract length isn't 1 or 3");
log.error("Contract length {} isn't equal 1 or 3", contract.getContractLengthYears());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

System.out.printf("Contract: %1$tA, %1td %1$tB %1$tY - %2$tA, %1td %2$tB %2$tY%n", contract.getStartDate(), rentalSummary.getEndDate());
System.out.printf("All rentals:%n");
rentalSummary.getRentals().forEach(rental -> System.out.println(rental.toString()));
rentalSummary.getNextRental().ifPresentOrElse(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

List<Rental> rentals = oneYearContractRentalGenerator.generateRentals(oneYearContract);
assertEquals(12, rentals.size());

for (Rental r : rentals) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, another way of asserting over collections is to use Assertions.assertThat which allow for some nice combinations of asserting very specific combinations in a single line. ( eg in this scenario you could use stuff like Assertions.assertThat(rentals).extracting("paid").containsExactly(List of expected results)).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed you used assertThat in the test below for some Strings, nice! Try it out on collections as well

assertEquals(12, rentals.size());

for (Rental r : rentals) {
boolean expectedPaid = !r.dueDate.isAfter(LocalDate.now());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally unit tests are used to check concrete examples which we know the expected results of, so that we can be sure the logic is working as expected, and to catch any regressions in the future. We tend not to use logic in unit tests and instead use real, assigned values. So rather than working out the expectedPaid value dynamically, we should really be hard-coding each expected boolean result.

This is where the Assertions.assertThat comes in handy, as instead of writing something like:

AssertTrue(rentals.get(0));
AssertTrue(rentals.get(1));
.
.
.
AssertFalse(rentals.get(x));
.
.
.
You can give it a single list of expected results.

Another point, can you think of any issues that could be caused by using LocalDate.now() in a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Review in progress 📅 Sprint 5 Assigned during Sprint 5 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants