Skip to content

Commit

Permalink
Fix QualityGate issues (#5923)
Browse files Browse the repository at this point in the history
Part of SLVS-1167
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 24, 2024
1 parent 9165b4a commit a51af9d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class BindingProcessFactoryTests
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<BindingProcessFactory, IBindingProcessFactory>(
MefTestHelpers.CreateExport<ISonarQubeService>(),
MefTestHelpers.CreateExport<IQualityProfileDownloader>(),
MefTestHelpers.CreateExport<ILogger>());
}
Expand All @@ -55,15 +54,13 @@ public void Create_ReturnsProcessImpl()
}

private static BindingProcessFactory CreateTestSubject(
ISonarQubeService service = null,
IQualityProfileDownloader qualityProfileDownloader = null,
ILogger logger = null)
{
service ??= Mock.Of<ISonarQubeService>();
qualityProfileDownloader ??= Mock.Of<IQualityProfileDownloader>();
logger ??= new TestLogger(logToConsole: true);

return new BindingProcessFactory(service, qualityProfileDownloader, logger);
return new BindingProcessFactory(qualityProfileDownloader, logger);
}

}
Expand Down
30 changes: 6 additions & 24 deletions src/ConnectedMode.UnitTests/Binding/BindingProcessImplTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.TestInfrastructure;
using SonarQube.Client;
using SonarQube.Client.Models;
using SonarQube.Client.Helpers;
using System.Security;

Expand All @@ -45,36 +44,22 @@ public void Ctor_ArgChecks()
{
var bindingArgs = CreateBindCommandArgs();
var qpDownloader = Mock.Of<IQualityProfileDownloader>();
var sonarQubeService = Mock.Of<ISonarQubeService>();
Mock.Of<ISonarQubeService>();
var logger = Mock.Of<ILogger>();

// 1. Null binding args
Action act = () => new BindingProcessImpl(null, sonarQubeService, qpDownloader, logger);
Action act = () => new BindingProcessImpl(null, qpDownloader, logger);
act.Should().ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("bindingArgs");

// 3. Null SonarQube service
act = () => new BindingProcessImpl(bindingArgs, null, qpDownloader, logger);
act.Should().ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("sonarQubeService");

// 4. Null QP downloader
act = () => new BindingProcessImpl(bindingArgs, sonarQubeService, null, logger);
// 2. Null QP downloader
act = () => new BindingProcessImpl(bindingArgs, null, logger);
act.Should().ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("qualityProfileDownloader");

// 5. Null logger
act = () => new BindingProcessImpl(bindingArgs, sonarQubeService, qpDownloader, null);
// 3. Null logger
act = () => new BindingProcessImpl(bindingArgs, qpDownloader, null);
act.Should().ThrowExactly<ArgumentNullException>().And.ParamName.Should().Be("logger");
}

private static ServerExclusions CreateSettings()
{
return new ServerExclusions
{
Inclusions = new string[] { "inclusion1", "inclusion2" },
Exclusions = new string[] { "exclusion" },
GlobalExclusions = new string[] { "globalExclusion" }
};
}

[TestMethod]
public async Task DownloadQualityProfile_CreatesBoundProjectAndCallsQPDownloader()
{
Expand Down Expand Up @@ -132,17 +117,14 @@ public async Task DownloadQualityProfile_HandlesInvalidOperationException()
#region Helpers

private BindingProcessImpl CreateTestSubject(BindCommandArgs bindingArgs = null,
ISonarQubeService sonarQubeService = null,
IQualityProfileDownloader qpDownloader = null,
ILogger logger = null)
{
bindingArgs = bindingArgs ?? CreateBindCommandArgs();
sonarQubeService ??= Mock.Of<ISonarQubeService>();
qpDownloader ??= Mock.Of<IQualityProfileDownloader>();
logger ??= new TestLogger(logToConsole: true);

return new BindingProcessImpl(bindingArgs,
sonarQubeService,
qpDownloader,
logger);
}
Expand Down
14 changes: 0 additions & 14 deletions src/ConnectedMode/Binding/BindingProcessImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,23 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using SonarLint.VisualStudio.ConnectedMode.Persistence;
using SonarLint.VisualStudio.ConnectedMode.QualityProfiles;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Analysis;
using SonarLint.VisualStudio.Core.Binding;
using SonarQube.Client;
using SonarQube.Client.Models;
using Language = SonarLint.VisualStudio.Core.Language;

namespace SonarLint.VisualStudio.ConnectedMode.Binding
{
internal class BindingProcessImpl : IBindingProcess
{
private readonly BindCommandArgs bindingArgs;
private readonly ISonarQubeService sonarQubeService;
private readonly IQualityProfileDownloader qualityProfileDownloader;
private readonly ILogger logger;

public BindingProcessImpl(
BindCommandArgs bindingArgs,
ISonarQubeService sonarQubeService,
IQualityProfileDownloader qualityProfileDownloader,
ILogger logger)
{
this.bindingArgs = bindingArgs ?? throw new ArgumentNullException(nameof(bindingArgs));
this.sonarQubeService = sonarQubeService ?? throw new ArgumentNullException(nameof(sonarQubeService));
this.qualityProfileDownloader = qualityProfileDownloader ?? throw new ArgumentNullException(nameof(qualityProfileDownloader));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
Expand Down
6 changes: 0 additions & 6 deletions src/ConnectedMode/Binding/IBindingProcessFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
using System.ComponentModel.Composition;
using SonarLint.VisualStudio.ConnectedMode.QualityProfiles;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Analysis;
using SonarQube.Client;

namespace SonarLint.VisualStudio.ConnectedMode.Binding
{
Expand All @@ -38,25 +36,21 @@ internal interface IBindingProcessFactory
[PartCreationPolicy(CreationPolicy.Shared)]
internal class BindingProcessFactory : IBindingProcessFactory
{
private readonly ISonarQubeService sonarQubeService;
private readonly IQualityProfileDownloader qualityProfileDownloader;
private readonly ILogger logger;

[ImportingConstructor]
public BindingProcessFactory(
ISonarQubeService sonarQubeService,
IQualityProfileDownloader qualityProfileDownloader,
ILogger logger)
{
this.sonarQubeService = sonarQubeService;
this.qualityProfileDownloader = qualityProfileDownloader;
this.logger = logger;
}

public IBindingProcess Create(BindCommandArgs bindingArgs)
{
return new BindingProcessImpl(bindingArgs,
sonarQubeService,
qualityProfileDownloader,
logger);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Integration.Vsix/SonarLintTagger/TaggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag

var tagger = singletonTaggerManager.CreateTagger(buffer);
return tagger as ITagger<T>;

return null;
}

private TextBufferIssueTracker InternalCreateTextBufferIssueTracker(ITextDocument textDocument, IEnumerable<AnalysisLanguage> analysisLanguages) =>
Expand Down

0 comments on commit a51af9d

Please sign in to comment.