File tree Expand file tree Collapse file tree
testing-modules/mockito/src/test/java/org/baeldung/mockito Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,18 +15,22 @@ public class MockAnnotationUnitTest {
1515 UserRepository mockRepository ;
1616
1717 @ Test
18- public void whenCountMethodIsMocked_ThenMockedValueIsReturned () {
18+ public void givenCountMethodMocked_WhenCountInvoked_ThenMockValueReturned () {
1919 Mockito .when (mockRepository .count ()).thenReturn (123L );
20+
2021 long userCount = mockRepository .count ();
22+
2123 Assert .assertEquals (123L , userCount );
2224 Mockito .verify (mockRepository ).count ();
2325 }
2426
2527 @ Test
26- public void whenLocalMockVariableIsUsed_ThenMockedValueFromLocalMockVariableIsReturned () {
28+ public void givenCountMethodOfLocalMockVariableMocked_WhenCountInvoked_ThenMockedValueReturned () {
2729 UserRepository localMockRepository = Mockito .mock (UserRepository .class );
2830 Mockito .when (localMockRepository .count ()).thenReturn (111L );
31+
2932 long userCount = localMockRepository .count ();
33+
3034 Assert .assertEquals (111L , userCount );
3135 Mockito .verify (localMockRepository ).count ();
3236 }
Original file line number Diff line number Diff line change @@ -20,10 +20,12 @@ public class MockBeanAnnotationIntegrationTest {
2020 ApplicationContext context ;
2121
2222 @ Test
23- public void whenCountMethodIsMocked_ThenMockedValueIsReturned () {
23+ public void givenCountMethodMocked_WhenCountInvokedOnBeanFromContext_ThenMockValueReturned () {
2424 Mockito .when (mockRepository .count ()).thenReturn (123L );
25+
2526 UserRepository userRepoFromContext = context .getBean (UserRepository .class );
2627 long userCount = userRepoFromContext .count ();
28+
2729 Assert .assertEquals (123L , userCount );
2830 Mockito .verify (mockRepository ).count ();
2931 }
You can’t perform that action at this time.
0 commit comments