🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Saves the course in the database
  2. B.Checks that findById was called
  3. C.Tells the mock to return that course when findById(1L) is called
  4. 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 →