PlannerDataObjectEditor extends ObjectEditor implements PlannerDataObjectEditorView.Presenter { RemoteCallback<List<Path>> getFindClassUsagesCallback() { return new RemoteCallback<List<Path>>() { @Override public void callback(List<Path> paths) { if (context != null) { List<Path> pathsCopy = new ArrayList<>(paths); Path currentDataObjectPath = context.getDataObjectPath(dataObject.getClassName()); pathsCopy.remove(currentDataObjectPath); view.enablePlanningSolutionCheckBox(pathsCopy.isEmpty()); view.showPlanningSolutionHelpIcon(!pathsCopy.isEmpty()); } } }; } @Inject  PlannerDataObjectEditor(PlannerDataObjectEditorView view,
                                   DomainHandlerRegistry handlerRegistry,
                                   Event<DataModelerEvent> dataModelerEvent,
                                   DataModelCommandBuilder commandBuilder,
                                   TranslationService translationService,
                                   Caller<ComparatorDefinitionService> comparatorDefinitionService,
                                   Caller<AssetsUsageService> assetsUsageServiceCaller); @Override Widget asWidget(); @Override String getName(); @Override String getDomainName(); @Override void clear(); @Override void objectPropertyPathChanged(List<ObjectPropertyPath> objectPropertyPaths,
                                          boolean itemsRemoved); @Override void removeComparatorDefinition(DataObject dataObject,
                                           boolean resetPlanningEntityAnnotation); @Override void onNotInPlanningChange(); @Override void onPlanningEntityChange(); @Override void onPlanningSolutionChange(); @Override void onPlanningSolutionScoreTypeChange(); @Override void onPlanningSolutionBendableScoreHardLevelsSizeChange(); @Override void onPlanningSolutionBendableScoreSoftLevelsSizeChange();  }
@Test public void getFindClassUsagesCallbackObjectIsAPlanningSolution() { PlannerDataObjectEditor objectEditor = createObjectEditor(); Path solutionPath = PathFactory.newPath("PlanningSolution.java", "default: Map<String, Path> dataObjectPaths = new HashMap<>(); dataObjectPaths.put("test.PlanningSolution", solutionPath); context.getEditorModelContent().setDataObjectPaths(dataObjectPaths); DataObject dataObject = new DataObjectImpl("test", "PlanningSolution"); context.setDataObject(dataObject); objectEditor.onContextChange(context); RemoteCallback<List<Path>> callback = objectEditor.getFindClassUsagesCallback(); Mockito.reset(view); callback.callback(Arrays.asList(solutionPath)); verify(view, times(1)).enablePlanningSolutionCheckBox(true); verify(view, times(1)).showPlanningSolutionHelpIcon(false); }
@Test public void getFindClassUsagesCallbackObjectIsNotAPlanningSolution() { PlannerDataObjectEditor objectEditor = createObjectEditor(); Path solutionPath = PathFactory.newPath("PlanningSolution.java", "default: Path entityPath = PathFactory.newPath("PlanningEntity.java", "default: Map<String, Path> dataObjectPaths = new HashMap<>(); dataObjectPaths.put("test.PlanningSolution", solutionPath); context.getEditorModelContent().setDataObjectPaths(dataObjectPaths); DataObject dataObject = new DataObjectImpl("test", "PlanningEntity"); context.setDataObject(dataObject); objectEditor.onContextChange(context); RemoteCallback<List<Path>> callback = objectEditor.getFindClassUsagesCallback(); Mockito.reset(view); callback.callback(Arrays.asList(solutionPath)); verify(view, times(1)).enablePlanningSolutionCheckBox(false); verify(view, times(1)).showPlanningSolutionHelpIcon(true); }
@Test public void getFindClassUsagesCallbackObjectWithoutContext() { PlannerDataObjectEditor objectEditor = createObjectEditor(); objectEditor.onContextChange(null); objectEditor.getFindClassUsagesCallback().callback(Collections.emptyList()); verify(view, never()).enablePlanningSolutionCheckBox(anyBoolean()); verify(view, never()).showPlanningSolutionHelpIcon(anyBoolean()); }