]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21643 Fix IT CompositeBlameCommandIT (#10709)
authorDejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>
Fri, 23 Feb 2024 16:18:02 +0000 (17:18 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 23 Feb 2024 20:02:36 +0000 (20:02 +0000)
sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java

index c14c2f6b78ee439084be391849477425f5500b56..d1332243431d4bc6a4f9166599acb008b8c02578 100644 (file)
@@ -125,28 +125,30 @@ class CompositeBlameCommandIT {
     Path expectedBlameFiles = new File(Utils.class.getResource("expected-blame/" + expectedBlameFolder).toURI()).toPath();
     Map<Path, List<BlameLine>> expectedBlame = new HashMap<>();
 
-    List<Path> filesInExpectedBlameFolder = Files.walk(expectedBlameFiles).filter(Files::isRegularFile).toList();
-    for (Path expectedFileBlamePath : filesInExpectedBlameFolder) {
-      List<BlameLine> blameLines = new ArrayList<>();
-      List<String> expectedBlameStrings = Files.readAllLines(expectedFileBlamePath);
-      for (String line : expectedBlameStrings) {
-        String revision = line.substring(0, 40);
-
-        int beginningEmail = line.indexOf("<") + 1, endEmail = line.indexOf(">");
-        String email = line.substring(beginningEmail, endEmail);
-
-        int beginningDate = line.indexOf("2", endEmail), dateLength = 25;
-        String sDate = line.substring(beginningDate, beginningDate + dateLength);
-        Date parsedDate = new Date(OffsetDateTime.parse(sDate).toInstant().toEpochMilli());
-
-        BlameLine blameLine = new BlameLine()
-          .revision(revision)
-          .author(email)
-          .date(parsedDate);
-
-        blameLines.add(blameLine);
+    try (Stream<Path> files = Files.walk(expectedBlameFiles)) {
+      List<Path> filesInExpectedBlameFolder = files.filter(Files::isRegularFile).toList();
+      for (Path expectedFileBlamePath : filesInExpectedBlameFolder) {
+        List<BlameLine> blameLines = new ArrayList<>();
+        List<String> expectedBlameStrings = Files.readAllLines(expectedFileBlamePath);
+        for (String line : expectedBlameStrings) {
+          String revision = line.substring(0, 40);
+
+          int beginningEmail = line.indexOf("<") + 1, endEmail = line.indexOf(">");
+          String email = line.substring(beginningEmail, endEmail);
+
+          int beginningDate = line.indexOf("2", endEmail), dateLength = 25;
+          String sDate = line.substring(beginningDate, beginningDate + dateLength);
+          Date parsedDate = new Date(OffsetDateTime.parse(sDate).toInstant().toEpochMilli());
+
+          BlameLine blameLine = new BlameLine()
+            .revision(revision)
+            .author(email)
+            .date(parsedDate);
+
+          blameLines.add(blameLine);
+        }
+        expectedBlame.put(expectedBlameFiles.relativize(expectedFileBlamePath), blameLines);
       }
-      expectedBlame.put(expectedBlameFiles.relativize(expectedFileBlamePath), blameLines);
     }
     return expectedBlame;
   }