Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (120 points)

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());

    }
}

Please log in or register to answer this question.

Related questions

Browse Categories

...