valentinacupac / banking-kata-java

Banking Kata (Java)
MIT License
336 stars 90 forks source link

Givens - Cleanup #78

Open valentinacupac opened 1 year ago

valentinacupac commented 1 year ago

Improvement 1

In OpenAccountUseCaseTest, there are repetitive lines of code regarding givenThat

        FakeNationalIdentityProviderGivens.givenThat(nationalIdentityProvider).contains(nationalIdentityNumber);
        FakeCustomerProviderGivens.givenThat(customerProvider).isValid(nationalIdentityNumber);
        FakeGenerationGivens.givenThat(accountIdGenerator).willGenerate(generatedAccountId);
        FakeGenerationGivens.givenThat(accountNumberGenerator).willGenerate(generatedAccountNumber);
        FakeTimeGivens.givenThat(dateTimeService).willReturn(LocalDateTime.of(openingDate, LocalTime.MIN));

And then classes FakeNationalIdentityProviderGiven and FakeNationalIdentityProviderGivens...

Need to think about consolidation...

Improvement 2

Perhaps there could be default time & fake number setup to handle tests that don't care about it? And then can override in tests which actually do care about it.

    @Test
    void should_throw_exception_given_nonexistent_national_identity_number() {
        FakeGenerationGivens.givenThat(accountIdGenerator).willGenerate(1001);
        FakeGenerationGivens.givenThat(accountNumberGenerator).willGenerate("1-0-0-1");
        FakeTimeGivens.givenThat(dateTimeService).willReturn(LocalDateTime.of(LocalDate.of(2021, 6, 15), LocalTime.MIN));

        var request = openAccountRequest()
                .build();

      verifyThat(useCase).withRequest(request).shouldThrowValidationException(ValidationMessages.NATIONAL_IDENTITY_NUMBER_NONEXISTENT);
    }

Improvement 3

The FakeGenerator can be tested once, in the base.

Improvement 4

Replace given by setup