← Quiz: Testing Spring Boot: all 10 questions
Quiz: Testing Spring Boot · Question 6 of 10
What does when(repository.findById(1L)).thenReturn(Optional.of(course)) do in a Mockito test?
What does when(repository.findById(1L)).thenReturn(Optional.of(course)) do in a Mockito test?
- A.Saves the course in the database
- B.Checks that findById was called
- C.Tells the mock to return that course when findById(1L) is called
- D.Creates a real repository
Answer & explanation
Correct answer: Tells the mock to return that course when findById(1L) is called
Stubbing decides what a fake dependency returns.
Can you get the rest right without peeking?
Take the timed Quiz: Testing Spring Boot quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →