Search in sources :

Example 76 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project hippo by NHS-digital-website.

the class S3SdkConnectorTest method abortsS3MultipartUploadRequest_onChunkUploadFailure.

@Test
public void abortsS3MultipartUploadRequest_onChunkUploadFailure() throws Exception {
    // given
    final String contentType = newRandomString();
    final String uploadId = newRandomString();
    given(s3ObjectKeyGenerator.generateObjectKey(fileName)).willReturn(objectKey);
    final InitiateMultipartUploadResult result = mock(InitiateMultipartUploadResult.class);
    given(result.getUploadId()).willReturn(uploadId);
    given(s3.initiateMultipartUpload(any())).willReturn(result);
    final InputStream uploadedFileInputStream = mock(InputStream.class);
    final RuntimeException expectedCauseException = new RuntimeException(newRandomString());
    given(s3.uploadPart(any(UploadPartRequest.class))).willThrow(expectedCauseException);
    try {
        // when
        s3Connector.uploadFile(uploadedFileInputStream, fileName, contentType);
        // then
        fail("Exception was expected but none has been thrown.");
    } catch (final RuntimeException actualException) {
        // assert upload request - abort
        final ArgumentCaptor<AbortMultipartUploadRequest> abortMultipartUploadRequestArgumentCaptor = ArgumentCaptor.forClass(AbortMultipartUploadRequest.class);
        then(s3).should().abortMultipartUpload(abortMultipartUploadRequestArgumentCaptor.capture());
        final AbortMultipartUploadRequest actualAbortRequest = abortMultipartUploadRequestArgumentCaptor.getValue();
        assertThat("Request aborted with correct bucket name", actualAbortRequest.getBucketName(), is(bucketName));
        assertThat("Request aborted with correct object key", actualAbortRequest.getKey(), is(objectKey));
        assertThat("Request aborted with correct upload id", actualAbortRequest.getUploadId(), is(uploadId));
        // assert upload request - exception
        assertThat("Exception is thrown with correct message.", actualException.getMessage(), is("Failed to upload file " + objectKey));
        assertThat("Exception is thrown with correct cause.", actualException.getCause(), is(sameInstance(expectedCauseException)));
    }
}
Also used : InitiateMultipartUploadResult(com.amazonaws.services.s3.model.InitiateMultipartUploadResult) ArgumentCaptor(org.mockito.ArgumentCaptor) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) UploadPartRequest(com.amazonaws.services.s3.model.UploadPartRequest) AbortMultipartUploadRequest(com.amazonaws.services.s3.model.AbortMultipartUploadRequest) Test(org.junit.Test)

Example 77 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project sonarqube by SonarSource.

the class XooBlameCommandTest method testBlameWithRelativeDate.

@Test
public void testBlameWithRelativeDate() throws IOException {
    File source = new File(baseDir, "src/foo.xoo");
    FileUtils.write(source, "sample content");
    File scm = new File(baseDir, "src/foo.xoo.scm");
    FileUtils.write(scm, "123,julien,-10\n234,julien,-10");
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
    fs.add(inputFile);
    BlameOutput result = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
    new XooBlameCommand().blame(input, result);
    Predicate<Date> datePredicate = argument -> {
        Date approximate = DateUtils.addDays(new Date(), -10);
        return argument.getTime() > approximate.getTime() - 5000 && argument.getTime() < approximate.getTime() + 5000;
    };
    ArgumentCaptor<List<BlameLine>> blameLinesCaptor = ArgumentCaptor.forClass(List.class);
    verify(result).blameResult(eq(inputFile), blameLinesCaptor.capture());
    assertThat(blameLinesCaptor.getValue()).extracting(BlameLine::date).allMatch(datePredicate);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Arrays(java.util.Arrays) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Date(java.util.Date) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BlameInput(org.sonar.api.batch.scm.BlameCommand.BlameInput) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) DateUtils(org.sonar.api.utils.DateUtils) Xoo(org.sonar.xoo.Xoo) Before(org.junit.Before) Predicate(java.util.function.Predicate) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) File(java.io.File) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Mockito.verify(org.mockito.Mockito.verify) BlameLine(org.sonar.api.batch.scm.BlameLine) List(java.util.List) Rule(org.junit.Rule) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 78 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project sonarqube by SonarSource.

the class FileSourceDataComputerTest method compute_calls_read_for_each_line_and_passe_read_error_to_fileSourceDataWarnings.

@Test
public void compute_calls_read_for_each_line_and_passe_read_error_to_fileSourceDataWarnings() {
    int lineCount = 1 + new Random().nextInt(10);
    List<String> lines = IntStream.range(0, lineCount).mapToObj(i -> "line" + i).collect(toList());
    when(sourceLinesRepository.readLines(FILE)).thenReturn(CloseableIterator.from(lines.iterator()));
    when(sourceLineReadersFactory.getLineReaders(FILE)).thenReturn(lineReaders);
    when(sourceLinesHashRepository.getLineHashesComputerToPersist(FILE)).thenReturn(lineHashesComputer);
    // mock an implementation that will call the ReadErrorConsumer in order to verify that the provided consumer is
    // doing what we expect: pass readError to fileSourceDataWarnings
    int randomStartPoint = new Random().nextInt(500);
    doAnswer(new Answer() {

        int i = randomStartPoint;

        @Override
        public Object answer(InvocationOnMock invocation) {
            Consumer<LineReader.ReadError> readErrorConsumer = invocation.getArgument(1);
            readErrorConsumer.accept(new LineReader.ReadError(LineReader.Data.SYMBOLS, i++));
            return null;
        }
    }).when(lineReaders).read(any(), any());
    underTest.compute(FILE, fileSourceDataWarnings);
    ArgumentCaptor<DbFileSources.Line.Builder> lineBuilderCaptor = ArgumentCaptor.forClass(DbFileSources.Line.Builder.class);
    verify(lineReaders, times(lineCount)).read(lineBuilderCaptor.capture(), any());
    assertThat(lineBuilderCaptor.getAllValues()).extracting(DbFileSources.Line.Builder::getSource).containsOnlyElementsOf(lines);
    assertThat(lineBuilderCaptor.getAllValues()).extracting(DbFileSources.Line.Builder::getLine).containsExactly(IntStream.range(1, lineCount + 1).boxed().toArray(Integer[]::new));
    ArgumentCaptor<LineReader.ReadError> readErrorCaptor = ArgumentCaptor.forClass(LineReader.ReadError.class);
    verify(fileSourceDataWarnings, times(lineCount)).addWarning(same(FILE), readErrorCaptor.capture());
    assertThat(readErrorCaptor.getAllValues()).extracting(LineReader.ReadError::getLine).containsExactly(IntStream.range(randomStartPoint, randomStartPoint + lineCount).boxed().toArray(Integer[]::new));
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LineHashesComputer(org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepositoryImpl.LineHashesComputer) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) DbFileSources(org.sonar.db.protobuf.DbFileSources) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SourceHashComputer(org.sonar.core.hash.SourceHashComputer) Random(java.util.Random) Changeset(org.sonar.ce.task.projectanalysis.scm.Changeset) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Before(org.junit.Before) Component(org.sonar.ce.task.projectanalysis.component.Component) Iterator(java.util.Iterator) CloseableIterator(org.sonar.core.util.CloseableIterator) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Random(java.util.Random) Consumer(java.util.function.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LineReader(org.sonar.ce.task.projectanalysis.source.linereader.LineReader) DbFileSources(org.sonar.db.protobuf.DbFileSources) Test(org.junit.Test)

Example 79 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method send_new_issues_notification_to_user_only_for_non_backdated_issues.

@Test
public void send_new_issues_notification_to_user_only_for_non_backdated_issues() {
    UserDto user = db.users().insertUser();
    Random random = new Random();
    Integer[] efforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10_000 * i).toArray(Integer[]::new);
    Integer[] backDatedEfforts = IntStream.range(0, 1 + random.nextInt(10)).mapToObj(i -> 10 + random.nextInt(100)).toArray(Integer[]::new);
    Duration expectedEffort = Duration.create(stream(efforts).mapToInt(i -> i).sum());
    List<DefaultIssue> issues = concat(stream(efforts).map(effort -> createIssue().setType(randomRuleType).setEffort(Duration.create(effort)).setAssigneeUuid(user.getUuid()).setCreationDate(new Date(ANALYSE_DATE))), stream(backDatedEfforts).map(effort -> createIssue().setType(randomRuleType).setEffort(Duration.create(effort)).setAssigneeUuid(user.getUuid()).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS)))).collect(toList());
    shuffle(issues);
    DiskCache.CacheAppender issueCache = this.protoIssueCache.newAppender();
    issues.forEach(issueCache::append);
    issueCache.close();
    analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList()));
    when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    verify(notificationService).deliver(newIssuesNotificationMock);
    verify(notificationService).deliverEmails(ImmutableSet.of(myNewIssuesNotificationMock));
    // old API compatibility
    verify(notificationService).deliver(myNewIssuesNotificationMock);
    verify(notificationFactory).newNewIssuesNotification(assigneeCacheCaptor.capture());
    verify(notificationFactory).newMyNewIssuesNotification(assigneeCacheCaptor.capture());
    verifyNoMoreInteractions(notificationFactory);
    verifyAssigneeCache(assigneeCacheCaptor, user);
    verify(myNewIssuesNotificationMock).setAssignee(any(UserDto.class));
    ArgumentCaptor<NewIssuesStatistics.Stats> statsCaptor = forClass(NewIssuesStatistics.Stats.class);
    verify(myNewIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), statsCaptor.capture());
    verify(myNewIssuesNotificationMock).setDebt(expectedEffort);
    NewIssuesStatistics.Stats stats = statsCaptor.getValue();
    assertThat(stats.hasIssues()).isTrue();
    // just checking all issues have been added to the stats
    DistributedMetricStatsInt severity = stats.getDistributedMetricStats(NewIssuesStatistics.Metric.RULE_TYPE);
    assertThat(severity.getOnCurrentAnalysis()).isEqualTo(efforts.length);
    assertThat(severity.getTotal()).isEqualTo(backDatedEfforts.length + efforts.length);
    verifyStatistics(context, 1, 1, 0);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Collections.shuffle(java.util.Collections.shuffle) NOTIF_TYPES(org.sonar.ce.task.projectanalysis.step.SendIssueNotificationsStep.NOTIF_TYPES) Duration(org.sonar.api.utils.Duration) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) NewIssuesStatistics(org.sonar.server.issue.notification.NewIssuesStatistics) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) ComputationStep(org.sonar.ce.task.step.ComputationStep) Collections.singleton(java.util.Collections.singleton) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) IssueTesting.newIssue(org.sonar.db.issue.IssueTesting.newIssue) Map(java.util.Map) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) ReportComponent.builder(org.sonar.ce.task.projectanalysis.component.ReportComponent.builder) Mockito.doReturn(org.mockito.Mockito.doReturn) NotificationService(org.sonar.server.notification.NotificationService) ProtoIssueCache(org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache) DbTester(org.sonar.db.DbTester) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Notification(org.sonar.api.notifications.Notification) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) BRANCH(org.sonar.db.component.BranchType.BRANCH) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) DistributedMetricStatsInt(org.sonar.server.issue.notification.DistributedMetricStatsInt) RuleKey(org.sonar.api.rule.RuleKey) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) Mockito.any(org.mockito.Mockito.any) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) ComponentTesting.newBranchComponent(org.sonar.db.component.ComponentTesting.newBranchComponent) Supplier(java.util.function.Supplier) RuleTesting.newRule(org.sonar.db.rule.RuleTesting.newRule) ArrayList(java.util.ArrayList) RuleType(org.sonar.api.rules.RuleType) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) Stream.concat(java.util.stream.Stream.concat) DefaultBranchImpl(org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl) Before(org.junit.Before) Component(org.sonar.ce.task.projectanalysis.component.Component) Tuple(org.assertj.core.groups.Tuple) BranchType(org.sonar.db.component.BranchType) RandomUtils.nextInt(org.apache.commons.lang.math.RandomUtils.nextInt) DefaultIssue(org.sonar.core.issue.DefaultIssue) Type(org.sonar.ce.task.projectanalysis.component.Component.Type) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) DiskCache(org.sonar.ce.task.projectanalysis.util.cache.DiskCache) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) ArgumentCaptor.forClass(org.mockito.ArgumentCaptor.forClass) NotificationFactory(org.sonar.ce.task.projectanalysis.notification.NotificationFactory) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) TemporaryFolder(org.junit.rules.TemporaryFolder) Project(org.sonar.server.project.Project) NewIssuesStatistics(org.sonar.server.issue.notification.NewIssuesStatistics) UserDto(org.sonar.db.user.UserDto) Duration(org.sonar.api.utils.Duration) DefaultIssue(org.sonar.core.issue.DefaultIssue) DiskCache(org.sonar.ce.task.projectanalysis.util.cache.DiskCache) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Date(java.util.Date) Project(org.sonar.server.project.Project) Random(java.util.Random) DistributedMetricStatsInt(org.sonar.server.issue.notification.DistributedMetricStatsInt) Test(org.junit.Test)

Example 80 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method sends_one_issue_change_notification_every_1000_issues.

@Test
public void sends_one_issue_change_notification_every_1000_issues() {
    UserDto user = db.users().insertUser();
    ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName());
    ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName());
    RuleDefinitionDto ruleDefinitionDto = newRule();
    RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)];
    List<DefaultIssue> issues = IntStream.range(0, 2001 + new Random().nextInt(10)).mapToObj(i -> newIssue(ruleDefinitionDto, project, file).setKee("uuid_" + i).setType(randomTypeExceptHotspot).toDefaultIssue().setNew(false).setChanged(true).setSendNotifications(true).setAssigneeUuid(user.getUuid())).collect(toList());
    DiskCache.CacheAppender cacheAppender = protoIssueCache.newAppender();
    issues.forEach(cacheAppender::append);
    cacheAppender.close();
    analysisMetadataHolder.setProject(Project.from(project));
    NewIssuesFactoryCaptor newIssuesFactoryCaptor = new NewIssuesFactoryCaptor(() -> mock(IssuesChangesNotification.class));
    when(notificationFactory.newIssuesChangesNotification(anySet(), anyMap())).thenAnswer(newIssuesFactoryCaptor);
    when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true);
    when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true);
    underTest.execute(new TestComputationStepContext());
    verify(notificationFactory, times(3)).newIssuesChangesNotification(anySet(), anyMap());
    assertThat(newIssuesFactoryCaptor.issuesSetCaptor).hasSize(3);
    assertThat(newIssuesFactoryCaptor.issuesSetCaptor.get(0)).hasSize(1000);
    assertThat(newIssuesFactoryCaptor.issuesSetCaptor.get(1)).hasSize(1000);
    assertThat(newIssuesFactoryCaptor.issuesSetCaptor.get(2)).hasSize(issues.size() - 2000);
    assertThat(newIssuesFactoryCaptor.assigneeCacheCaptor).hasSize(3);
    assertThat(newIssuesFactoryCaptor.assigneeCacheCaptor).containsOnly(newIssuesFactoryCaptor.assigneeCacheCaptor.iterator().next());
    ArgumentCaptor<Collection> collectionCaptor = forClass(Collection.class);
    verify(notificationService, times(3)).deliverEmails(collectionCaptor.capture());
    assertThat(collectionCaptor.getAllValues()).hasSize(3);
    assertThat(collectionCaptor.getAllValues().get(0)).hasSize(1);
    assertThat(collectionCaptor.getAllValues().get(1)).hasSize(1);
    assertThat(collectionCaptor.getAllValues().get(2)).hasSize(1);
    verify(notificationService, times(3)).deliver(any(IssuesChangesNotification.class));
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Collections.shuffle(java.util.Collections.shuffle) NOTIF_TYPES(org.sonar.ce.task.projectanalysis.step.SendIssueNotificationsStep.NOTIF_TYPES) Duration(org.sonar.api.utils.Duration) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) NewIssuesStatistics(org.sonar.server.issue.notification.NewIssuesStatistics) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) ComputationStep(org.sonar.ce.task.step.ComputationStep) Collections.singleton(java.util.Collections.singleton) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) IssueTesting.newIssue(org.sonar.db.issue.IssueTesting.newIssue) Map(java.util.Map) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) ReportComponent.builder(org.sonar.ce.task.projectanalysis.component.ReportComponent.builder) Mockito.doReturn(org.mockito.Mockito.doReturn) NotificationService(org.sonar.server.notification.NotificationService) ProtoIssueCache(org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache) DbTester(org.sonar.db.DbTester) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) System2(org.sonar.api.utils.System2) Notification(org.sonar.api.notifications.Notification) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) BRANCH(org.sonar.db.component.BranchType.BRANCH) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) DistributedMetricStatsInt(org.sonar.server.issue.notification.DistributedMetricStatsInt) RuleKey(org.sonar.api.rule.RuleKey) TreeRootHolderRule(org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule) Mockito.any(org.mockito.Mockito.any) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) ComponentTesting.newBranchComponent(org.sonar.db.component.ComponentTesting.newBranchComponent) Supplier(java.util.function.Supplier) RuleTesting.newRule(org.sonar.db.rule.RuleTesting.newRule) ArrayList(java.util.ArrayList) RuleType(org.sonar.api.rules.RuleType) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) Stream.concat(java.util.stream.Stream.concat) DefaultBranchImpl(org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl) Before(org.junit.Before) Component(org.sonar.ce.task.projectanalysis.component.Component) Tuple(org.assertj.core.groups.Tuple) BranchType(org.sonar.db.component.BranchType) RandomUtils.nextInt(org.apache.commons.lang.math.RandomUtils.nextInt) DefaultIssue(org.sonar.core.issue.DefaultIssue) Type(org.sonar.ce.task.projectanalysis.component.Component.Type) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) DiskCache(org.sonar.ce.task.projectanalysis.util.cache.DiskCache) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) ArgumentCaptor.forClass(org.mockito.ArgumentCaptor.forClass) NotificationFactory(org.sonar.ce.task.projectanalysis.notification.NotificationFactory) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) TemporaryFolder(org.junit.rules.TemporaryFolder) Project(org.sonar.server.project.Project) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) RuleType(org.sonar.api.rules.RuleType) DefaultIssue(org.sonar.core.issue.DefaultIssue) DiskCache(org.sonar.ce.task.projectanalysis.util.cache.DiskCache) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Random(java.util.Random) Collection(java.util.Collection) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Test(org.junit.Test)

Aggregations

ArgumentCaptor (org.mockito.ArgumentCaptor)231 Mockito.verify (org.mockito.Mockito.verify)156 List (java.util.List)128 Test (org.junit.Test)116 Mockito.mock (org.mockito.Mockito.mock)113 Mockito.when (org.mockito.Mockito.when)100 Test (org.junit.jupiter.api.Test)86 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)85 Mockito (org.mockito.Mockito)85 Map (java.util.Map)76 BeforeEach (org.junit.jupiter.api.BeforeEach)72 Arrays (java.util.Arrays)69 Collectors (java.util.stream.Collectors)69 Collections (java.util.Collections)68 Before (org.junit.Before)65 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)64 Mockito.times (org.mockito.Mockito.times)64 ArrayList (java.util.ArrayList)60 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)60 Mockito.never (org.mockito.Mockito.never)58