Axelor Unit Test

Hi All, I’m new to this forum and Axelor
I’m trying to write an Axelor Unit test.
I use axelor-erp application, after writing a new method for LeaveRequestImpl.java, I would like to write some test to perform multiple scenario testing for that method.

I need to mock other services and repositories.

Someone know how to or has some example to show me?

public boolean existTimesheetUnderReviewSameTime(LeaveRequest leaveRequest)
  throws AxelorException {

List<Timesheet> timesheetList =
    this.timesheetService.getTimesheetForEmployeeAndCompanyId(
        leaveRequest.getUser().getEmployee(), leaveRequest.getCompany());

LocalDateTime leaveRequestFromDateT = leaveRequest.getFromDateT();

for (Timesheet timesheet : timesheetList) {
  if (timesheet.getStatusSelect() == TimesheetRepository.STATUS_CONFIRMED
      || timesheet.getStatusSelect() == TimesheetRepository.STATUS_REFUSED
      || timesheet.getStatusSelect() == TimesheetRepository.STATUS_VALIDATED) {
    if (leaveRequestFromDateT.isAfter(timesheet.getFromDate().atStartOfDay())
        && leaveRequestFromDateT.isBefore(timesheet.getToDate().atStartOfDay())) {
      return true;
    }
  }
}
return false;

}

I want to mock properly timesheetService and its repository to generate multiple query scenario.

Thanks All!

Unit test code following:

Log error:
Unable to create injector, see the following errors:

  1. No implementation for com.axelor.apps.account.service.AccountManagementAccountService was bound.
    while locating com.axelor.apps.account.service.AccountManagementAccountService
    for the 1st parameter of com.axelor.apps.account.service.move.MoveLineService.(MoveLineService.java:102)
    while locating com.axelor.apps.account.service.move.MoveLineService
    for the 3rd parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  2. No implementation for com.axelor.apps.account.service.AccountManagementAccountService was bound.
    while locating com.axelor.apps.account.service.AccountManagementAccountService
    for the 4th parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  3. No implementation for com.axelor.apps.account.service.AccountingSituationService was bound.
    while locating com.axelor.apps.account.service.AccountingSituationService
    for the 7th parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  4. No implementation for com.axelor.apps.account.service.AnalyticMoveLineService was bound.
    while locating com.axelor.apps.account.service.AnalyticMoveLineService
    for the 5th parameter of com.axelor.apps.account.service.move.MoveLineService.(MoveLineService.java:102)
    while locating com.axelor.apps.account.service.move.MoveLineService
    for the 3rd parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  5. No implementation for com.axelor.apps.account.service.AnalyticMoveLineService was bound.
    while locating com.axelor.apps.account.service.AnalyticMoveLineService
    for the 8th parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  6. No implementation for com.axelor.apps.account.service.FiscalPositionAccountService was bound.
    while locating com.axelor.apps.account.service.FiscalPositionAccountService
    for the 3rd parameter of com.axelor.apps.account.service.move.MoveLineService.(MoveLineService.java:102)
    while locating com.axelor.apps.account.service.move.MoveLineService
    for the 3rd parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  7. No implementation for com.axelor.apps.account.service.app.AppAccountService was bound.
    while locating com.axelor.apps.account.service.app.AppAccountService
    for the 4th parameter of com.axelor.apps.account.service.move.MoveLineService.(MoveLineService.java:102)
    while locating com.axelor.apps.account.service.move.MoveLineService
    for the 3rd parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  8. No implementation for com.axelor.apps.account.service.app.AppAccountService was bound.
    while locating com.axelor.apps.account.service.app.AppAccountService
    for the 1st parameter of com.axelor.apps.hr.service.batch.BatchCreditTransferExpensePaymentHR.(BatchCreditTransferExpensePaymentHR.java:60)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:102) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)

  9. No implementation for com.axelor.apps.account.service.app.AppAccountService was bound.
    while locating com.axelor.apps.account.service.app.AppAccountService
    for the 5th parameter of com.axelor.apps.hr.service.expense.ExpenseServiceImpl.(ExpenseServiceImpl.java:125)
    at com.axelor.apps.hr.module.HumanResourceModule.configure(HumanResourceModule.java:94) (via modules: com.axelor.apps.hr.service.leave.LeaveServiceTest$MyModule → com.axelor.apps.hr.module.HumanResourceModule)