ScenarioSimulationGridHeaderUtilities { public static boolean isEditableHeader(final ScenarioGridColumn column, final Integer uiHeaderRowIndex) { final GridColumn.HeaderMetaData headerMetaData = column.getHeaderMetaData().get(uiHeaderRowIndex); if (!(headerMetaData instanceof ScenarioHeaderMetaData)) { throw new IllegalStateException("Header metadata has to be an instance of ScenarioHeaderMetaData"); } final ScenarioHeaderMetaData scenarioHeaderMetaData = (ScenarioHeaderMetaData) headerMetaData; if (scenarioHeaderMetaData.isEditingMode() || scenarioHeaderMetaData.isReadOnly()) { return false; } if (!column.isInstanceAssigned() || !column.isEditableHeaders()) { return false; } return scenarioHeaderMetaData.isInstanceHeader() || (scenarioHeaderMetaData.isPropertyHeader() && column.isPropertyAssigned()); }  static ScenarioHeaderMetaData getColumnScenarioHeaderMetaData(GridWidget gridWidget, Point2D relativePoint); static ScenarioHeaderMetaData getColumnScenarioHeaderMetaData(final ScenarioGridColumn scenarioGridColumn,
                                                                         final int uiRowIndex); static GridColumn<?> getGridColumn(GridWidget gridWidget, double cx); static boolean isEditableHeader(final ScenarioGridColumn column,
                                           final Integer uiHeaderRowIndex); static EnableTestToolsEvent getEnableTestToolsEvent(final ScenarioGrid scenarioGrid,
                                                               final ScenarioGridColumn scenarioGridColumn,
                                                               final ScenarioHeaderMetaData clickedScenarioHeaderMetadata,
                                                               final Integer uiColumnIndex,
                                                               final String columnGroup); static String getExistingInstances(final String group,
                                              final ScenarioSimulationModel.Type scenarioType,
                                              final List<GridColumn<?>> columns); static List<String> getPropertyNameElements(final AbstractScesimGridModel abstractScesimGridModel, final int columnIndex);  }
@Test public void testIsHeaderEditableNorInstanceNorPropertyAssigned() { final boolean result = ScenarioSimulationGridHeaderUtilities.isEditableHeader(scenarioGridColumnOne, 0); assertThat(result).as("Nor Instance nor Property assigned").isFalse(); }
@Test public void testIsHeaderEditableInstanceAssignedAndSelected() { when(scenarioGridColumnOne.isInstanceAssigned()).thenReturn(true); final ScenarioHeaderMetaData metaDataMock = (ScenarioHeaderMetaData) scenarioGridColumnOne.getHeaderMetaData().get(0); when(metaDataMock.isInstanceHeader()).thenReturn(true); final boolean result = ScenarioSimulationGridHeaderUtilities.isEditableHeader(scenarioGridColumnOne, 0); assertThat(result).as("Instance Assigned and selected").isTrue(); }
@Test public void testIsHeaderEditableInstanceAssignedButPropertySelected() { when(scenarioGridColumnOne.isInstanceAssigned()).thenReturn(true); final ScenarioHeaderMetaData metaDataMock = (ScenarioHeaderMetaData) scenarioGridColumnOne.getHeaderMetaData().get(0); when(metaDataMock.isPropertyHeader()).thenReturn(true); final boolean result = ScenarioSimulationGridHeaderUtilities.isEditableHeader(scenarioGridColumnOne, 0); assertThat(result).as("Instance Assigned but Property selected").isFalse(); }
@Test public void testIsHeaderEditableInstanceAndPropertyAssignedButNotSelected() { when(scenarioGridColumnOne.isInstanceAssigned()).thenReturn(true); when(scenarioGridColumnOne.isPropertyAssigned()).thenReturn(true); final ScenarioHeaderMetaData metaDataMock = (ScenarioHeaderMetaData) scenarioGridColumnOne.getHeaderMetaData().get(0); when(metaDataMock.isPropertyHeader()).thenReturn(false); when(metaDataMock.isInstanceHeader()).thenReturn(false); final boolean result = ScenarioSimulationGridHeaderUtilities.isEditableHeader(scenarioGridColumnOne, 0); assertThat(result).as("Instance and Property Assigned but not selected").isFalse(); }
@Test public void testIsHeaderEditableInstanceAndPropertyAssignedAndPropertySelected() { when(scenarioGridColumnOne.isInstanceAssigned()).thenReturn(true); when(scenarioGridColumnOne.isPropertyAssigned()).thenReturn(true); final ScenarioHeaderMetaData metaDataMock = (ScenarioHeaderMetaData) scenarioGridColumnOne.getHeaderMetaData().get(0); when(metaDataMock.isPropertyHeader()).thenReturn(true); final boolean result = ScenarioSimulationGridHeaderUtilities.isEditableHeader(scenarioGridColumnOne, 0); assertThat(result).as("Instance and Property Assigned and Property selected").isTrue(); }
@Test public void testHeaderMetadataInstanceOf() { final ScenarioGridColumn invalidColumn = mockGridColumn(100, Collections.singletonList(mock(GridColumn.HeaderMetaData.class))); assertThatThrownBy(() -> ScenarioSimulationGridHeaderUtilities.isEditableHeader(invalidColumn, 0)) .isInstanceOf(IllegalStateException.class) .hasMessage("Header metadata has to be an instance of ScenarioHeaderMetaData"); }