I am mocking a service layer and stubbing one of the method but doReturn doesnt return the mocked value. Bellow is my code, what i am doing wrong
public class Service
{
@Autowired
Dao dao;
....
public int doSomething(){
return 2;
}
}
@Category(IntegrationTest.class)
@RunWith(SpringRunner.class)
public class Test{
@Autowired
Service instanceOfService;
@Test
public void testMethod(){
Service mockedService = Mockito.spy(instanceOfService)
Mockito.doReturn(4).when(mockedService).doSomething();
Assert.assertEquals(4, mockedService.doSomething());
}
}