Trying to mock SQLQueryFactory of Querydsl for DAO unit testing. Using Mockito's deep stub for the very first time. Below is the minimal code which fails
@Test
void tryMockQueryDsl() {
SQLQueryFactory sql = Mockito.mock(SQLQueryFactory.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(sql.select(ArgumentMatchers.<Expression<?>>any())
.from(ArgumentMatchers.<Expression<?>>any())
.fetchFirst()
).thenReturn(null);
}
with the following exception:
java.lang.ClassCastException: class com.querydsl.sql.ProjectableSQLQuery$MockitoMock$1584151766 cannot be cast to class com.querydsl.sql.SQLQuery (com.querydsl.sql.ProjectableSQLQuery$MockitoMock$1584151766 and com.querydsl.sql.SQLQuery are in unnamed module of loader 'app')
What can be the problem?