use of org.mockito.ArgumentCaptor in project sonarqube by SonarSource.
the class SvnBlameCommandTest method testParsingOfOutputWithMergeHistory.
@Test
public void testParsingOfOutputWithMergeHistory() throws Exception {
File repoDir = unzip("repo-svn-with-merge.zip");
String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
File baseDir = new File(checkout(scmUrl), "dummy-svn/trunk");
when(fs.baseDir()).thenReturn(baseDir);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setLines(27).setModuleBaseDir(baseDir.toPath()).build();
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(singletonList(inputFile));
newSvnBlameCommand().blame(input, blameResult);
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
verify(blameResult).blameResult(eq(inputFile), captor.capture());
List<BlameLine> result = captor.getValue();
assertThat(result).hasSize(27);
Date commitDate = new Date(1342691097393L);
Date revision6Date = new Date(1415262184300L);
BlameLine[] expected = IntStream.rangeClosed(1, 27).mapToObj(i -> {
if (i == 2 || i == 24) {
return new BlameLine().date(revision6Date).revision("6").author("henryju");
} else {
return new BlameLine().date(commitDate).revision("2").author("dgageot");
}
}).toArray(BlameLine[]::new);
assertThat(result).containsExactly(expected);
}
use of org.mockito.ArgumentCaptor in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testSetDisplayNameMultipleOutputClauseWithNonEmptyValue.
@Test
@SuppressWarnings("unchecked")
public void testSetDisplayNameMultipleOutputClauseWithNonEmptyValue() {
setupGrid(makeHasNameForDecision(), 0);
final String defaultName = "default-name";
final Consumer<ValueAndDataTypeHeaderMetaData> test = (md) -> md.setValue(new Name(NAME_NEW));
addOutputClause(3);
final ArgumentCaptor<CompositeCommand> compositeCommandCaptor1 = ArgumentCaptor.forClass(CompositeCommand.class);
hasExpression.getName().setValue(defaultName);
expression.get().getOutput().get(0).setName(defaultName);
assertHeaderMetaDataTest(0, 2, test, compositeCommandCaptor1, SetHasValueCommand.class, UpdateElementPropertyCommand.class);
compositeCommandCaptor1.getValue().execute(canvasHandler);
assertThat(hasExpression.getName().getValue()).isEqualTo(NAME_NEW);
assertThat(expression.get().getOutput().get(0).getName()).isEqualTo(defaultName);
final ArgumentCaptor<CompositeCommand> compositeCommandCaptor2 = ArgumentCaptor.forClass(CompositeCommand.class);
hasExpression.getName().setValue(defaultName);
expression.get().getOutput().get(0).setName(defaultName);
assertHeaderMetaDataTest(1, 2, test, compositeCommandCaptor2, SetHasValueCommand.class);
compositeCommandCaptor2.getValue().execute(canvasHandler);
assertThat(hasExpression.getName().getValue()).isEqualTo(defaultName);
assertThat(expression.get().getOutput().get(0).getName()).isEqualTo(NAME_NEW);
final ArgumentCaptor<CompositeCommand> compositeCommandCaptor3 = ArgumentCaptor.forClass(CompositeCommand.class);
hasExpression.getName().setValue(defaultName);
expression.get().getOutput().get(1).setName(defaultName);
assertHeaderMetaDataTest(0, 3, test, compositeCommandCaptor3, SetHasValueCommand.class, UpdateElementPropertyCommand.class);
compositeCommandCaptor3.getValue().execute(canvasHandler);
assertThat(hasExpression.getName().getValue()).isEqualTo(NAME_NEW);
assertThat(expression.get().getOutput().get(1).getName()).isEqualTo(defaultName);
final ArgumentCaptor<CompositeCommand> compositeCommandCaptor4 = ArgumentCaptor.forClass(CompositeCommand.class);
hasExpression.getName().setValue(defaultName);
expression.get().getOutput().get(1).setName(defaultName);
assertHeaderMetaDataTest(1, 3, test, compositeCommandCaptor4, SetHasValueCommand.class);
compositeCommandCaptor4.getValue().execute(canvasHandler);
assertThat(hasExpression.getName().getValue()).isEqualTo(defaultName);
assertThat(expression.get().getOutput().get(0).getName()).isEqualTo(NAME_NEW);
}
use of org.mockito.ArgumentCaptor in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method executeWithMultiSelection.
@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelection() {
pasteSelectionSessionCommand.bind(session);
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(true);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(false);
// Mock the callback of CloneNodeCommand
ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
when(cloneNodeCommand.getCandidate()).thenReturn(node);
when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {
{
put(node, consumerNode);
put(node2, consumerNode2);
}
};
// Mock the callback of CloneConnectorCommand
ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
when(canvasCommandFactory.cloneConnector(any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
// apply callbacks mocks
when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
CompositeCommand argument = param.getArgument(1, CompositeCommand.class);
// callback to nodes
argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
Node candidate = cloneNodeCommand.getCandidate();
consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
});
// callback to connectors
argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
return commandResult;
});
// Executing the command
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
CopySelectionSessionCommand.getInstance(sessionManager).bind(session);
pasteSelectionSessionCommand.execute(callback);
verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), any());
// check command registry update after execution to allow a single undo/redo
verify(commandRegistry, times(2)).pop();
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
assertEquals(2, ((CompositeCommand) commandArgumentCaptor.getValue()).size());
}
use of org.mockito.ArgumentCaptor in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method executeWithMultiSelectionWithEdgesClipboard.
@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelectionWithEdgesClipboard() {
final Connection sourceConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getSourceConnection().orElse(null);
final Connection targetConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getTargetConnection().orElse(null);
final EdgeClipboard clipboard = clipboardControl.buildNewEdgeClipboard(graphInstance.startNode.getUUID(), sourceConnection, graphInstance.intermNode.getUUID(), targetConnection);
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
final Map<String, EdgeClipboard> map = new HashMap<>();
map.put(graphInstance.edge1.getUUID(), clipboard);
when(clipboardControl.getEdgeMap()).thenReturn(map);
assertEquals(1, clipboardControl.getEdgeMap().size());
pasteSelectionSessionCommand.bind(session);
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(false);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(true);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge1));
assertEquals(true, pasteSelectionSessionCommand.isEdgeFoundInClipboard(graphInstance.edge1));
// Mock the callback of CloneNodeCommand
ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
when(cloneNodeCommand.getCandidate()).thenReturn(node);
when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {
{
put(node, consumerNode);
put(node2, consumerNode2);
}
};
// Mock the callback of CloneConnectorCommand
ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
when(canvasCommandFactory.cloneConnector(any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
// apply callbacks mocks
when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
CompositeCommand argument = param.getArgument(1, CompositeCommand.class);
// callback to nodes
argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
Node candidate = cloneNodeCommand.getCandidate();
consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
});
// callback to connectors
argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
return commandResult;
});
// Executing the command
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
CopySelectionSessionCommand.getInstance(sessionManager).bind(session);
pasteSelectionSessionCommand.execute(callback);
verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), any());
// check command registry update after execution to allow a single undo/redo
verify(commandRegistry, times(2)).pop();
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
assertEquals(2, ((CompositeCommand) commandArgumentCaptor.getValue()).size());
}
use of org.mockito.ArgumentCaptor in project wikidata-query-rdf by wikimedia.
the class KafkaPollerUnitTest method storedOffsetsFromBoth.
@Test
public void storedOffsetsFromBoth() throws RetryableException {
// Scenario where all offsets are loaded from both storage and timestamp
Collection<String> topics = ImmutableList.of("topictest", "othertopic", "thirdtopic");
KafkaOffsetsRepository offsetsRepository = mock(KafkaOffsetsRepository.class);
createTopicPartitions(1);
// capture args for assign
ArgumentCaptor<Collection<TopicPartition>> assignArgs = ArgumentCaptor.forClass((Class) Collection.class);
doNothing().when(consumer).assign(assignArgs.capture());
// capture args for seek
ArgumentCaptor<TopicPartition> seekTopics = ArgumentCaptor.forClass(TopicPartition.class);
ArgumentCaptor<Long> seekOffsets = ArgumentCaptor.forClass(Long.class);
doNothing().when(consumer).seek(seekTopics.capture(), seekOffsets.capture());
// Stored offsets
Map<TopicPartition, OffsetAndTimestamp> offsetMap = ImmutableMap.of(new TopicPartition("topictest", 0), new OffsetAndTimestamp(1, START_TIME.toEpochMilli()), new TopicPartition("othertopic", 0), new OffsetAndTimestamp(3, START_TIME.toEpochMilli()));
when(offsetsRepository.load(any())).thenReturn(offsetMap);
// Timestamp-driven offsets
when(consumer.offsetsForTimes(any())).thenAnswer(i -> {
Map<TopicPartition, Long> map = i.getArgumentAt(0, Map.class);
// Check that timestamps are OK
map.forEach((k, v) -> assertThat(v).isEqualTo(START_TIME.toEpochMilli()));
// All offsets are 500
return map.entrySet().stream().collect(Collectors.toMap(Entry::getKey, l -> new OffsetAndTimestamp(500L, l.getValue())));
});
when(consumer.poll(anyLong())).thenReturn(EMPTY_CHANGES);
KafkaPoller poller = new KafkaPoller(consumer, uris, START_TIME, BATCH_SIZE, topics, offsetsRepository, false, new MetricRegistry());
Batch batch = poller.firstBatch();
// should not call offsetsForTimes, since all offsets are in store
verify(consumer, times(1)).offsetsForTimes(any());
// We assign to 3 topics
verify(consumer, times(1)).assign(any());
assertThat(assignArgs.getValue()).hasSize(topics.size());
assertThat(seekOffsets.getAllValues()).hasSize(topics.size()).contains(// This offset is from timestamp
500L);
}
Aggregations