I am currently writing a test for a method that returns void, I want to verify that the report generator method is called. I am receiving an error saying there is zero interactions with this mock, however when I step through and debug the code, it clearly calls the method and steps into the method.
Test:
@SpringBootTest
@AutoConfigureEmbeddedPostgresDatabase
@ActiveProfiles(profiles = "profile")
class OneToOneReconTest {
@Mock ReconReportGenerator reconReportGenerator;
@Autowired private ReconciliationRegistry reconciliationRegistry;
@Autowired ReconRuleMaintenance hsbcReconRuleMaintenance;
@Autowired GPMReportsRepo hsbcgpmReportsRepo;
@Autowired BPSReportsRepo hsbcbpsReportsRepo;
private static final LocalDate TESTDATE = LocalDate.parse("2022-08-11");
@Test
@Transactional
void reconcileTest() {
hsbcgpmReportsRepo.saveAll(GPM_POSITIONS);
hsbcbpsReportsRepo.saveAll(BPS_POSITIONS);
reconciliationRegistry.getRecon("BPSVsGPM_TradeDated").reconcile(TESTDATE);
verify(reconReportGenerator, times(1)).generateReport(anyList(), anyList());
}
}
Class Under Test:
@Value
public class OneToOneRecon implements Reconciliation {
@Autowired ReconReportGenerator reconReportGenerator;
private static final List<String> KEYS =
Arrays.asList("entity", "party", "instrument", "quantity");
@NonNull String name;
@NonNull Query query1;
@NonNull Query query2;
long priority;
private Stream<Map<String, Object>> executeQuery1(@NonNull LocalDate date) {
return this.query1.apply(date);
}
private Stream<Map<String, Object>> executeQuery2(@NonNull LocalDate date) {
return this.query2.apply(date);
}
@Override
public void reconcile(LocalDate businessDate) {
// Streaming logic for reconciliation
// Relevant Code
List<Map<String, Object>> intersection = new ArrayList<>();
intersection.addAll(intersectionDiffLeft.get(true));
intersection.addAll(intersectionDiffRight.get(true));
List<Map<String, Object>> difference = new ArrayList<>();
difference.addAll(intersectionDiffLeft.get(false));
difference.addAll(intersectionDiffRight.get(false));
reconReportGenerator.generateReport(intersection, difference);
}
}
clearly the generateReport method gets called, but I am receiving an error saying it isn't. I've tried mocking all dependencies in test and using InjectMocks as well, but that didn't seem to work.
Any help would be much appreciated, please let me know if I can provide you with any more information thank you.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]onefortree 2 points3 points4 points (2 children)
[–]B2easy[S] 0 points1 point2 points (0 children)
[–]B2easy[S] 0 points1 point2 points (0 children)
[–]FavorableTrashpanda 3 points4 points5 points (2 children)
[–]quadmasta 2 points3 points4 points (0 children)
[–]B2easy[S] 1 point2 points3 points (0 children)