Skip to content

Commit 1504979

Browse files
ghislainpiotsonartech
authored andcommitted
SONARPY-3145 Increase coverage of Error branch in the CompletableFuture exception handling (#357)
GitOrigin-RevId: 6feb846c827dcf179a3bf627cb8f8063d122625b
1 parent 608e25c commit 1504979

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

python-commons/src/test/java/org/sonar/plugins/python/PythonSensorTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,30 @@ void test_exception_should_fail_analysis_if_configured_so() throws IOException {
696696
.hasCauseInstanceOf(FileNotFoundException.class);
697697
}
698698

699+
@Test
700+
void test_completion_exception_with_error() throws IOException {
701+
activeRules = new ActiveRulesBuilder().build();
702+
703+
DefaultInputFile inputFile = spy(TestInputFileBuilder.create("moduleKey", FILE_1)
704+
.setModuleBaseDir(baseDir.toPath())
705+
.setCharset(UTF_8)
706+
.setType(Type.MAIN)
707+
.setLanguage(Python.KEY)
708+
.initMetadata(TestUtils.fileContent(new File(baseDir, FILE_1), UTF_8))
709+
.setStatus(InputFile.Status.ADDED)
710+
.build());
711+
when(inputFile.contents()).thenThrow(new OutOfMemoryError("Test out of memory error"));
712+
713+
context.fileSystem().add(inputFile);
714+
715+
context.setSettings(new MapSettings().setProperty("sonar.python.analysis.threads", "2"));
716+
PythonSensor sensor = sensor();
717+
718+
assertThatThrownBy(() -> sensor.execute(context))
719+
.isInstanceOf(OutOfMemoryError.class)
720+
.hasMessage("Test out of memory error");
721+
}
722+
699723
@Test
700724
void test_python_version_parameter_warning() {
701725
context.fileSystem().add(inputFile(FILE_1).wrappedFile());

0 commit comments

Comments
 (0)