From e3b7560d2da5deae95f8a89339db3e312e8aeb7a Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 8 Nov 2024 10:17:40 +0100 Subject: [PATCH] JS-402 Fix PRAnalysisTest (#4895) --- .../it/plugin/assertj/BuildResultAssert.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java index 615776cde03..70a9345ebf3 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java @@ -21,7 +21,6 @@ import static java.lang.String.format; import static java.util.regex.Pattern.compile; -import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.tuple; @@ -147,10 +146,19 @@ public BuildResultAssert generatesUcfgFilesForAll(Path projectPath, String... fi List ucfgFiles; try { ucfgFiles = findUcfgFilesIn(projectPath); - for (var filename : filenames) { + for (var ucfgFile : ucfgFiles) { + // Filenames: file2_SomeLambdaFunction_yaml + // ucfgFile: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit14107160890921213721/pr-analysis-yaml/.scannerwork/ucfg2/js/daFunction_yaml_1.ucfgs + // We check if file2_SomeLambdaFunction_yaml ends with daFunction_yaml + // or + // Filenames: index.ts + // ucfg: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit2107948845245431806/pr-analysis-ts/.scannerwork/ucfg2/js/sis_ts_index_ts.ucfgs + // We check if sis_ts_index_ts ends with index_ts + + var key = ucfgFile.getFileName().toString().replaceFirst("(_\\d+)?[.][^.]+$", ""); // We remove index and extension: _1.ucfgs Assertions - .assertThat(ucfgFiles) - .filteredOn(file -> file.getFileName().toString().contains(filename.replace('.', '_'))) + .assertThat(filenames) + .filteredOn(filename -> filename.replace('.', '_').endsWith(key) || key.endsWith(filename.replace('.', '_'))) .isNotEmpty(); } } catch (IOException e) {