I have been trying to find an approach to write a simple unit test case for the below function , but not able to figure out anything . The function basically uses JPA Query on a QueryDSL Q class and returns the result as a Map. Any sample code would suffice . How do I mock the entire JPA Query to return a Map .
@Autowired
EntityManager entityManager;
public Map<Integer, Double> getUsersCategoryAppliedBudgetMap(int opportunityTypeId, LocalDate startDate,
LocalDate endDate) {
QApplications applicationPath = QApplications.applications;
JPAQuery<ApplicationApprovals> query = new JPAQuery<>(entityManager);
log.info("Executing Budget Query for opportunity type" + opportunityTypeId);
return query.from(applicationPath).where(applicationPath.applicationStatus.id
.in(PENDING_APPROVAL.getId(), SENT_BACK.getId(), APPROVED.getId(), PENDING_WITHDRAW_APPROVAL.getId(),
PENDING_COMPLETION_DOCUMENT.getId(), REVIEW_COMPLETION_DOCUMENT.getId(), COMPLETED.getId())
.and(applicationPath.opportunity.opportunityTypes.id.eq(opportunityTypeId))
.and(applicationPath.appliedDate.between(startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX))))
.groupBy(applicationPath.user.id)
.transform(GroupBy.groupBy(applicationPath.user.id).as(applicationPath.cost.sum()));
}