Handle the case with no test data populators

Since there is no populator yet Spring fails when trying to inject since it does not support empty collections. Mark the dependency as optional until we have at least one populator at which point we can simply the code again.
This commit is contained in:
Andreas Svanberg 2025-03-03 13:50:27 +01:00
parent a76b317b1c
commit 12ca344cfc

@ -42,7 +42,7 @@ public class DataInitializer implements Lifecycle, BaseData, Factory {
public static final long RESEARCH_AREA_ID = 12L;
@Inject
private Collection<TestDataPopulator> testDataPopulators = new ArrayList<>();
private Optional<Collection<TestDataPopulator>> testDataPopulators = Optional.empty();
@Inject
private UserService userService;
@ -123,7 +123,8 @@ public class DataInitializer implements Lifecycle, BaseData, Factory {
createTarget();
createStudentIdea();
createRoughDraftApproval();
for (TestDataPopulator testDataPopulator : testDataPopulators) {
Collection<TestDataPopulator> availablePopulators = testDataPopulators.orElseGet(Collections::emptySet);
for (TestDataPopulator testDataPopulator : availablePopulators) {
testDataPopulator.populate(this, this);
}
}