]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 2 May 2024 13:04:30 +0000 (15:04 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 2 May 2024 20:02:38 +0000 (20:02 +0000)
sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/http/ScannerWsClientProviderTest.java

index 8320b9dc0e7574df2e0c82a2d4785bf5297752ac..d7e0f7fc758963f5d105cc7e3db6d700e8495be8 100644 (file)
@@ -57,9 +57,11 @@ class BootstrapMediumIT {
   @BeforeEach
   void mockBareMinimalServerEndpoints() {
     sonarqube.stubFor(get("/api/plugins/installed")
-      .willReturn(okJson("{\n"
-        + "  \"plugins\": []\n"
-        + "}")));
+      .willReturn(okJson("""
+        {
+          "plugins": []
+        }
+        """)));
 
     sonarqube.stubFor(get("/api/qualityprofiles/search.protobuf?project=" + PROJECT_KEY)
       .willReturn(aResponse()
@@ -77,17 +79,21 @@ class BootstrapMediumIT {
           .build()))));
 
     sonarqube.stubFor(get("/api/languages/list")
-      .willReturn(okJson("{\n"
-        + "  \"languages\": []\n"
-        + "}")));
+      .willReturn(okJson("""
+        {
+          "languages": []
+        }
+        """)));
 
     sonarqube.stubFor(get("/api/metrics/search?ps=500&p=1")
-      .willReturn(okJson("{\n"
-        + "  \"metrics\": [],\n"
-        + "  \"total\": 0,\n"
-        + "  \"p\": 1,\n"
-        + "  \"ps\": 100"
-        + "}")));
+      .willReturn(okJson("""
+        {
+          "metrics": [],
+          "total": 0,
+          "p": 1,
+          "ps": 100
+        }
+        """)));
 
     sonarqube.stubFor(post("/api/ce/submit?projectKey=" + PROJECT_KEY)
       .willReturn(aResponse()
index 9d8522a897fd2b231cd63f92055388dbad6ad6e5..2a27b7c5653e4682689983c990b970f8283cd5d8 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.scanner.bootstrap;
 
-import com.google.common.collect.ImmutableMap;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
@@ -49,7 +48,7 @@ class GlobalTempFolderProviderTest {
     Files.delete(workingDir);
 
     var tempFolder = underTest.provide(
-      new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.toAbsolutePath().toString())), sonarUserHome);
+      new ScannerProperties(Map.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.toAbsolutePath().toString())), sonarUserHome);
     tempFolder.newDir();
     tempFolder.newFile();
 
@@ -71,7 +70,7 @@ class GlobalTempFolderProviderTest {
     }
 
     underTest.provide(
-      new ScannerProperties(ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.toAbsolutePath().toString())), sonarUserHome);
+      new ScannerProperties(Map.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, workingDir.toAbsolutePath().toString())), sonarUserHome);
 
     // this also checks that all other temps were deleted
     assertThat(workingDir.toFile().list()).hasSize(1);
@@ -88,7 +87,7 @@ class GlobalTempFolderProviderTest {
   }
 
   @Test
-  void createTempFolderFromSonarHome(@TempDir Path sonarUserHomePath) throws Exception {
+  void createTempFolderFromSonarHome(@TempDir Path sonarUserHomePath) {
     // with sonar home, it will be in {sonar.home}/.sonartmp
     when(sonarUserHome.getPath()).thenReturn(sonarUserHomePath);
     
@@ -109,7 +108,7 @@ class GlobalTempFolderProviderTest {
     when(sonarUserHome.getPath()).thenReturn(sonarUserHomePath);
     String globalWorkDir = ".";
     ScannerProperties globalProperties = new ScannerProperties(
-      ImmutableMap.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, globalWorkDir));
+      Map.of(CoreProperties.GLOBAL_WORKING_DIRECTORY, globalWorkDir));
 
     var tempFolder = underTest.provide(globalProperties, sonarUserHome);
     File newFile = tempFolder.newFile();
index 907e13f92bc875e477263e940b997ed724496787..97d33f200fa93b07d0f87e1105a6e34d3cd6845e 100644 (file)
@@ -78,7 +78,7 @@ class PluginFilesTest {
   private PluginFiles underTest;
 
   @BeforeEach
-  void setUp(@TempDir Path sonarUserHomeDir) throws Exception {
+  void setUp(@TempDir Path sonarUserHomeDir) {
     when(sonarUserHome.getPath()).thenReturn(sonarUserHomeDir);
 
     HttpConnector connector = HttpConnector.newBuilder().acceptGzip(true).url(sonarqube.url("/")).build();
index e0ee3121accc01a4e3936701a6f7f2b2c5d2fd8c..e605999ddd34831f797144cd7f6765f78ba61612 100644 (file)
@@ -66,9 +66,7 @@ class ScannerWsClientProviderTest {
   private static final GlobalAnalysisMode GLOBAL_ANALYSIS_MODE = new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()));
   private static final AnalysisWarnings ANALYSIS_WARNINGS = warning -> {
   };
-  @TempDir
-  private Path sonarUserHomeDir;
-  private final SonarUserHome sonarUserHome = mock(SonarUserHome.class);
+  private SonarUserHome sonarUserHome = mock(SonarUserHome.class);
   private final Map<String, String> scannerProps = new HashMap<>();
 
   private final ScannerWsClientProvider underTest = new ScannerWsClientProvider();
@@ -78,9 +76,9 @@ class ScannerWsClientProviderTest {
   private final Properties systemProps = new Properties();
 
   @BeforeEach
-  void configureMocks() {
+  void configureMocks(@TempDir Path sonarUserHomeDir) {
     when(system2.properties()).thenReturn(systemProps);
-    when(sonarUserHome.getPath()).thenReturn(sonarUserHomeDir);
+    sonarUserHome = new SonarUserHome(sonarUserHomeDir);
   }
 
   @Test