From: Dejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:18:02 +0000 (+0100) Subject: SONAR-21643 Fix IT CompositeBlameCommandIT (#10709) X-Git-Tag: 10.5.0.89998~168 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e2e4ca5594431f7ed596d7da93dfc21656c02ddb;p=sonarqube.git SONAR-21643 Fix IT CompositeBlameCommandIT (#10709) --- diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java index c14c2f6b78e..d1332243431 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/CompositeBlameCommandIT.java @@ -125,28 +125,30 @@ class CompositeBlameCommandIT { Path expectedBlameFiles = new File(Utils.class.getResource("expected-blame/" + expectedBlameFolder).toURI()).toPath(); Map> expectedBlame = new HashMap<>(); - List filesInExpectedBlameFolder = Files.walk(expectedBlameFiles).filter(Files::isRegularFile).toList(); - for (Path expectedFileBlamePath : filesInExpectedBlameFolder) { - List blameLines = new ArrayList<>(); - List 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 files = Files.walk(expectedBlameFiles)) { + List filesInExpectedBlameFolder = files.filter(Files::isRegularFile).toList(); + for (Path expectedFileBlamePath : filesInExpectedBlameFolder) { + List blameLines = new ArrayList<>(); + List 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; }