### Question:
RelationUIModelMapper extends BaseUIModelMapper<Relation> { @Override public void toDMNModel(final int rowIndex, final int columnIndex, final Supplier<Optional<GridCellValue<?>>> cell) { dmnModel.get().ifPresent(relation -> { final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, columnIndex); switch (section) { case ROW_INDEX: break; case INFORMATION_ITEM: final org.kie.workbench.common.dmn.api.definition.model.List row = relation.getRow().get(rowIndex); final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, columnIndex); final HasExpression hasExpression = row.getExpression().get(iiIndex); final Expression e = hasExpression.getExpression(); final Optional<Expression> expression = Optional.ofNullable(e); expression.ifPresent(ex -> { final LiteralExpression le = (LiteralExpression) ex; le.getText().setValue((String) cell.get().orElse(new BaseGridCellValue<>("")).getValue()); }); } }); } RelationUIModelMapper(final Supplier<GridData> uiModel,
                                 final Supplier<Optional<Relation>> dmnModel,
                                 final ListSelectorView.Presenter listSelector,
                                 final double lineHeight); @Override void fromDMNModel(final int rowIndex,
                             final int columnIndex); @Override void toDMNModel(final int rowIndex,
                           final int columnIndex,
                           final Supplier<Optional<GridCellValue<?>>> cell);  }### Answer:
@Test public void testToDMNModelLiteralExpressionsNullValue() { cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(null)); for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) { for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) { mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier); final LiteralExpression le = (LiteralExpression) relation .getRow() .get(uiRowIndex) .getExpression() .get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT) .getExpression(); assertNull(le.getText().getValue()); } } }
@Test public void testToDMNModelLiteralExpressionsEmptyValue() { for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) { for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) { mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier); final LiteralExpression le = (LiteralExpression) relation .getRow() .get(uiRowIndex) .getExpression() .get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT) .getExpression(); assertEquals("", le.getText().getValue()); } } }
@Test public void testToDMNModelLiteralExpressionsNonEmptyValue() { for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) { for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) { final String value = "(" + uiColumnIndex + "," + uiRowIndex + ")"; cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(value)); mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier); final LiteralExpression le = (LiteralExpression) relation .getRow() .get(uiRowIndex) .getExpression() .get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT) .getExpression(); assertEquals(value, le.getText().getValue()); } } }