Repository navigation
Conversation
| 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()); |
| 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( |
| List<Rental> rentals = oneYearContractRentalGenerator.generateRentals(oneYearContract); | ||
| assertEquals(12, rentals.size()); | ||
|
|
||
| for (Rental r : rentals) { |
There was a problem hiding this comment.
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)).
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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?
Learners, PR Template
Self checklist
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
ThreeYearsGeneratorbecause they would be the same, and also I thinkoneYearGeneratorandThreeYearsGeneratorshould be one function, since they are sharing the same functionalityQuestions
Instead of generating a mock list of rentals and verifying against that, I just checked some properties of the list. Is it alright?