Java - Import for mockito, Mockito's when returns an object of class OngoingStubbing. This class has a method thenReturn (), and that's what gets called in your example code. No additional import is needed. when (myDao.fetchTree (anyLong ())).thenReturn (myTreeList); could be broken...