The code snippet retrieves the entity based on parameters.
public void updateNotification(String status, Entity entity ) {
Entity entity1 = null;
try {
switch (status) {
case "AX":
entity1 = this.Repository.findByTypeAndParams(
1, entity.getParam1(), entity.getParam2(),
entity.getParam3());
if (entity1!= null) {
entity1.setCurrentStatusKey("SET");
updateEntity(entity1);
} else {
LOGGER.debug("");
}
break;
Test case for the above code :
@RunWith(SpringJUnit4ClassRunner.class)
public class ServiceTest {
@InjectMocks
CVService cVServiceMock;
@Mock
RepositoryMock repositoryMock;
@Test
public void testUpdateOut() {
Entity entity1 = new Entity ();
entity1.setType(2);
Mockito.when(repositoryMock.findByTypeAndParams(any(Integer.class), any(String.class),
any(String.class), any(String.class))).thenReturn(entity1);
cVServiceMock.updateNotification("AX", entity1);
}
The entity1 is always null instead of mocked entity when executed from the test case, what am i doing wrong here?