Renamed test methods to use BDD style

This commit is contained in:
priyeshmashelkar 2018-07-17 10:52:19 +01:00
parent 0522b91f3d
commit 4b46635ac7
2 changed files with 9 additions and 3 deletions

View File

@ -15,18 +15,22 @@ public class MockAnnotationUnitTest {
UserRepository mockRepository; UserRepository mockRepository;
@Test @Test
public void whenCountMethodIsMocked_ThenMockedValueIsReturned() { public void givenCountMethodMocked_WhenCountInvoked_ThenMockValueReturned() {
Mockito.when(mockRepository.count()).thenReturn(123L); Mockito.when(mockRepository.count()).thenReturn(123L);
long userCount = mockRepository.count(); long userCount = mockRepository.count();
Assert.assertEquals(123L, userCount); Assert.assertEquals(123L, userCount);
Mockito.verify(mockRepository).count(); Mockito.verify(mockRepository).count();
} }
@Test @Test
public void whenLocalMockVariableIsUsed_ThenMockedValueFromLocalMockVariableIsReturned() { public void givenCountMethodOfLocalMockVariableMocked_WhenCountInvoked_ThenMockedValueReturned() {
UserRepository localMockRepository = Mockito.mock(UserRepository.class); UserRepository localMockRepository = Mockito.mock(UserRepository.class);
Mockito.when(localMockRepository.count()).thenReturn(111L); Mockito.when(localMockRepository.count()).thenReturn(111L);
long userCount = localMockRepository.count(); long userCount = localMockRepository.count();
Assert.assertEquals(111L, userCount); Assert.assertEquals(111L, userCount);
Mockito.verify(localMockRepository).count(); Mockito.verify(localMockRepository).count();
} }

View File

@ -20,10 +20,12 @@ public class MockBeanAnnotationIntegrationTest {
ApplicationContext context; ApplicationContext context;
@Test @Test
public void whenCountMethodIsMocked_ThenMockedValueIsReturned() { public void givenCountMethodMocked_WhenCountInvokedOnBeanFromContext_ThenMockValueReturned() {
Mockito.when(mockRepository.count()).thenReturn(123L); Mockito.when(mockRepository.count()).thenReturn(123L);
UserRepository userRepoFromContext = context.getBean(UserRepository.class); UserRepository userRepoFromContext = context.getBean(UserRepository.class);
long userCount = userRepoFromContext.count(); long userCount = userRepoFromContext.count();
Assert.assertEquals(123L, userCount); Assert.assertEquals(123L, userCount);
Mockito.verify(mockRepository).count(); Mockito.verify(mockRepository).count();
} }