use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class DecisionServiceParametersListWidgetTest method testGetCurrentItems.
@Test
public void testGetCurrentItems() {
final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
final DecisionService decisionService = mock(DecisionService.class);
final String id1 = "id1";
final String id2 = "id2";
final String id3 = "id3";
final List<DMNElementReference> list = createListOfDMNElementReferenceWithIds(id1, id2, id3);
final List<InputData> unsortedInputs = Arrays.asList(createInputDataWithId(id2), createInputDataWithId(id3), createInputDataWithId(id1));
doReturn(value).when(widget).getValue();
when(value.getDecisionService()).thenReturn(decisionService);
when(decisionService.getInputData()).thenReturn(list);
final List<InputData> sorted = widget.getCurrentItems(unsortedInputs);
assertThat(sorted).extracting(inputData -> inputData.getId().getValue()).containsExactly(id1, id2, id3);
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class DecisionServiceParametersListWidgetTest method testGetNewItems.
@Test
public void testGetNewItems() {
final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
final DecisionService decisionService = mock(DecisionService.class);
final String id1 = "id1";
final String id2 = "id2";
final String id3 = "id3";
final String newItem1 = "aaa";
final String newItem2 = "bbb";
final String newItem3 = "ccc";
final String newItem4 = "ddd";
final List<DMNElementReference> list = createListOfDMNElementReferenceWithIds(id1, id2, id3);
final List<InputData> currentItems = Arrays.asList(createInputDataWithId(id2), createInputDataWithId(id3), createInputDataWithId(id1));
final List<InputData> inputs = Arrays.asList(createInputDataWithId(newItem3), createInputDataWithId(newItem2), createInputDataWithId(newItem4), createInputDataWithId(newItem1));
doReturn(value).when(widget).getValue();
when(value.getDecisionService()).thenReturn(decisionService);
when(decisionService.getInputData()).thenReturn(list);
final List<InputData> result = widget.getNewItems(inputs, currentItems);
assertThat(result).extracting(inputData -> inputData.getId().getValue()).containsExactly(newItem1, newItem2, newItem3, newItem4);
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class BaseExpressionGridGeneralTest method testUpdateWidthOfPeers.
/*
* Test that parent column width is updated to sum of nested columns
* The update is forced from nested column at position indexOfColumnToUpdate
* The default width of parent column is 100
*/
private void testUpdateWidthOfPeers(final int indexOfColumnToUpdate, final double... widthsOfNestedColumns) {
// parent column
final BaseExpressionGrid parentGrid = mock(BaseExpressionGrid.class);
final GridData parentGridData = mock(GridData.class);
when(parentGrid.getModel()).thenReturn(parentGridData);
when(parentGrid.getExpression()).thenReturn(Optional::empty);
final DMNGridColumn parentColumn = mockColumn(100, parentGrid);
when(parentCell.getGridWidget()).thenReturn(parentGrid);
when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentColumn));
when(parentGridData.getColumnCount()).thenReturn(widthsOfNestedColumns.length);
when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(parentGrid));
// nested columns
final List<DMNGridColumn> columns = Arrays.stream(widthsOfNestedColumns).mapToObj(width -> mockColumn(width, grid)).collect(Collectors.toList());
grid.getModel().appendRow(new BaseGridRow());
columns.stream().forEach(column -> grid.getModel().appendColumn(column));
// force the peers width update
columns.get(indexOfColumnToUpdate).updateWidthOfPeers();
// assert parent width is equal to sum of nested columns widths
final double padding = BaseExpressionGrid.DEFAULT_PADDING * 2;
Assertions.assertThat(parentColumn.getWidth()).isEqualTo(Arrays.stream(widthsOfNestedColumns).sum() + padding);
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class DecisionServiceParametersListWidgetTest method testGetSortedInputs.
@Test
public void testGetSortedInputs() {
final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
final DecisionService decisionService = mock(DecisionService.class);
final String id1 = "id1";
final String id2 = "id2";
final String id3 = "id3";
final String newId1 = "newId1";
final String newId2 = "newId2";
final List<DMNElementReference> list = createListOfDMNElementReferenceWithIds(id1, id2, id3);
final List<InputData> unsortedInputs = Arrays.asList(createInputDataWithId(id2), createInputDataWithId(id3), createInputDataWithId(newId2), createInputDataWithId(id1), createInputDataWithId(newId1));
doReturn(value).when(widget).getValue();
when(value.getDecisionService()).thenReturn(decisionService);
when(decisionService.getInputData()).thenReturn(list);
final List<InputData> sorted = widget.getSortedInputs(unsortedInputs);
assertThat(sorted).extracting(inputData -> inputData.getId().getValue()).containsExactly(id1, id2, id3, newId1, newId2);
}
use of org.mockito.Mock in project kie-wb-common by kiegroup.
the class ValidationActionTest method loadingCompletedOnSuccess.
@Test
public void loadingCompletedOnSuccess() {
final Command loadingCompleted = mock(Command.class);
new ValidationAction(editorSessionCommands, () -> {
/* */
}, loadingCompleted, s -> {
/* */
}).validate();
verify(validateSessionCommand).execute(violationsArgumentCapture.capture());
violationsArgumentCapture.getValue().onSuccess();
verify(loadingCompleted).execute();
}
Aggregations