reflectoring / reflectoring.github.io

reflectoring blog
https://reflectoring.io
45 stars 55 forks source link

Mistake? in blog post "Integration Tests with @SpringBootTests #310

Closed s-gbz closed 4 years ago

s-gbz commented 4 years ago

I'm slightly confused concerning the mentioned blog post.

Here's the code example of the passage

    // given
    User user = new User("Zaphod", "zaphod@galaxy.net");
    boolean sendWelcomeMail = true;
    given(userRepository.save(any(UserEntity.class))).willReturn(userEntity(1L));

    // when
    Long userId = registerUseCase.registerUser(user, sendWelcomeMail);

    // then
    assertThat(userId).isEqualTo(1L);

We see given being used in the example. The passage mentions when though:

Using Mockito’s when method, we have specified the expected behavior for this mock in order to test a class that uses this repository.

Is that a mixup or "unfortunate wording"? Thanks again for the quality content 💯

thombergs commented 4 years ago

@s-gbz thanks for mentioning this! Fixed it! I probably refactored the code and copied it in after having written the text.