How to verify chained method calls?

Viewed 1762

I'm writing tests for my project's DAO class. But when I use Mockito's verify() method it throws NullPointerException because of createQuery() method returns null. How can I fix this?

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private EntityManager entityManagerMock;

@InjectMocks
private TaksitPlanSatiriDao taksitPlanSatiriDao = new TaksitPlanSatiriDaoJpa();

@Before
public void setUp() {
    taksitPlanSatiriEntity = new TaksitPlanSatiriEntity();
}
@Test
public void shouldUpdateWhenGuncelleCalledWithTaksitPlanSatiriEntity() {
    taksitPlanSatiriDao.guncelle(taksitPlanSatiriEntity);
    Mockito.verify(entityManagerMock).createQuery(ArgumentMatchers.anyString()).executeUpdate();
}
1 Answers
Related