PlannerDataModelerHelperUtils { public void updateDataObject(Path dataObjectPath) { String dataObjectString = ioService.readAllString(Paths.convert(dataObjectPath)); GenerationResult generationResult = dataModelerService.loadDataObject(dataObjectPath, dataObjectString, dataObjectPath); DataObject dataObject = generationResult.getDataObject(); if (dataObject != null && (generationResult.getErrors() == null || generationResult.getErrors().isEmpty())) { JavaClass comparatorObject = getComparatorObject(dataObject); if (comparatorObject != null) { JavaClass updatedComparatorObject = comparatorDefinitionService.updateComparatorObject(dataObject, comparatorObject); dataObject.removeNestedClass(comparatorObject); dataObject.addNestedClass(updatedComparatorObject); Annotation planningEntityAnnotation = dataObject.getAnnotation(PlanningEntity.class.getName()); if (planningEntityAnnotation != null) { planningEntityAnnotation.setValue("difficultyComparatorClass", dataObject.getName() + ".DifficultyComparator"); } generationResult = dataModelerService.updateSource(dataObjectString, dataObjectPath, dataObject); if (generationResult.getDataObject() != null && generationResult.getErrors() == null || generationResult.getErrors().isEmpty()) { ioService.write(Paths.convert(dataObjectPath), generationResult.getSource()); } else { logger.error("Data object " + dataObject.getClassName() + " couldn't be updated, path: " + dataObjectPath + "."); } } } else { logger.error("Data object couldn't be loaded, path: " + dataObjectPath + "."); } } PlannerDataModelerHelperUtils(); @Inject  PlannerDataModelerHelperUtils(@Named("ioStrategy") IOService ioService,
                                         ComparatorDefinitionService comparatorDefinitionService,
                                         DataModelerService dataModelerService); void updateDataObject(Path dataObjectPath);  }
@Test public void generationResultHasErrors() { generationResult.setErrors(Collections.singletonList(mock(DataModelerError.class))); DataObject dataObject = mock(DataObject.class); generationResult.setDataObject(dataObject); plannerDataModelerHelperUtils.updateDataObject(dataObjectPath); verify(dataObject, never()).getAnnotation(any()); }
@Test public void dataObjectIsNull() { generationResult.setDataObject(null); plannerDataModelerHelperUtils.updateDataObject(dataObjectPath); }
@Test public void generationResultErrorsIsNull() { generationResult.setErrors(null); DataObject dataObject = mock(DataObject.class); generationResult.setDataObject(dataObject); plannerDataModelerHelperUtils.updateDataObject(dataObjectPath); verify(dataObject).getAnnotation(any()); }
@Test public void generationResultErrorsIsEmpty() { generationResult.setErrors(Collections.emptyList()); DataObject dataObject = mock(DataObject.class); generationResult.setDataObject(dataObject); plannerDataModelerHelperUtils.updateDataObject(dataObjectPath); verify(dataObject).getAnnotation(any()); }