1515import static org .junit .jupiter .api .Assertions .*;
1616import static org .mockito .ArgumentMatchers .any ;
1717import static org .mockito .ArgumentMatchers .anyLong ;
18- import static org .mockito .Mockito .verify ;
19- import static org .mockito .Mockito .when ;
18+ import static org .mockito .BDDMockito .given ;
19+ import static org .mockito .BDDMockito .then ;
20+ import static org .mockito .Mockito .*;
2021
2122@ ExtendWith (MockitoExtension .class )
2223class VisitSDJpaServiceTest {
@@ -30,22 +31,25 @@ class VisitSDJpaServiceTest {
3031 @ Test
3132 void findAll () {
3233 Set <Visit > visits = new HashSet <>(Set .of (new Visit (), new Visit ()));
33- when (visitRepository .findAll ()).thenReturn (visits );
34+ given (visitRepository .findAll ()).willReturn (visits );
3435 Set <Visit > foundVisits = service .findAll ();
3536 assertNotNull (foundVisits );
3637 assertEquals (visits .size (), foundVisits .size ());
3738 assertEquals (visits , foundVisits );
38- verify (visitRepository ).findAll ();
39+ then (visitRepository ).should ().findAll ();
40+ then (visitRepository ).shouldHaveNoMoreInteractions ();
3941 }
4042
4143 @ Test
4244 void findById () {
4345 Visit visit = new Visit ();
44- when (visitRepository .findById (1L )).thenReturn (Optional .of (visit ));
46+ given (visitRepository .findById (1L )).willReturn (Optional .of (visit ));
4547 Visit foundVisit = service .findById (1L );
4648 assertNotNull (foundVisit );
4749 assertEquals (visit , foundVisit );
48- verify (visitRepository ).findById (1L );
50+ then (visitRepository ).should ().findById (1L );
51+ then (visitRepository ).should (never ()).findById (5L );
52+ then (visitRepository ).shouldHaveNoMoreInteractions ();
4953 }
5054
5155 @ Test
0 commit comments