use of org.sonar.java.exceptions.ApiMismatchException in project sonar-java by SonarSource.
the class VisitorsBridgeTest method canSkipScanningOfUnchangedFiles_returns_based_on_context.
@Test
void canSkipScanningOfUnchangedFiles_returns_based_on_context() throws ApiMismatchException {
SonarComponents sonarComponents = mock(SonarComponents.class);
VisitorsBridge vb = new VisitorsBridge(Collections.emptyList(), Collections.emptyList(), sonarComponents);
doReturn(true).when(sonarComponents).canSkipUnchangedFiles();
assertThat(vb.canSkipScanningOfUnchangedFiles()).isTrue();
doReturn(false).when(sonarComponents).canSkipUnchangedFiles();
assertThat(vb.canSkipScanningOfUnchangedFiles()).isFalse();
ApiMismatchException exception = new ApiMismatchException(new NoSuchMethodError());
doThrow(exception).when(sonarComponents).canSkipUnchangedFiles();
assertThat(vb.canSkipScanningOfUnchangedFiles()).isFalse();
}
use of org.sonar.java.exceptions.ApiMismatchException in project sonar-java by SonarSource.
the class SonarComponentsTest method fileCanBeSkipped_returns_false_when_canSkipUnchangedFile_isFalse.
@Test
void fileCanBeSkipped_returns_false_when_canSkipUnchangedFile_isFalse() throws ApiMismatchException {
SonarComponents sonarComponents = mock(SonarComponents.class, CALLS_REAL_METHODS);
ApiMismatchException apiMismatchException = new ApiMismatchException(new NoSuchMethodError("API version mismatch :-("));
doThrow(apiMismatchException).when(sonarComponents).canSkipUnchangedFiles();
assertThat(sonarComponents.fileCanBeSkipped(mock(InputFile.class))).isFalse();
}
use of org.sonar.java.exceptions.ApiMismatchException in project sonar-java by SonarSource.
the class SonarComponentsTest method skipUnchangedFiles_throws_a_NoSuchMethodError_when_canSkipUnchangedFiles_not_in_API.
@Test
void skipUnchangedFiles_throws_a_NoSuchMethodError_when_canSkipUnchangedFiles_not_in_API() {
SensorContextTester sensorContextTester = SensorContextTester.create(new File(""));
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, sensorContextTester.fileSystem(), mock(ClasspathForMain.class), mock(ClasspathForTest.class), checkFactory);
IncrementalAnalysisSensorContext context = mock(IncrementalAnalysisSensorContext.class);
when(context.canSkipUnchangedFiles()).thenThrow(new NoSuchMethodError("API version mismatch :-("));
sonarComponents.setSensorContext(context);
ApiMismatchException error = assertThrows(ApiMismatchException.class, sonarComponents::canSkipUnchangedFiles);
assertThat(error).hasCause(new NoSuchMethodError("API version mismatch :-("));
}
use of org.sonar.java.exceptions.ApiMismatchException in project sonar-java by SonarSource.
the class SonarComponentsTest method canSkipUnchangedFiles.
@ParameterizedTest
@MethodSource("provideInputsFor_canSkipUnchangedFiles")
void canSkipUnchangedFiles(@CheckForNull Boolean overrideFlagVal, @CheckForNull Boolean apiResponseVal, @CheckForNull Boolean expectedResult) throws ApiMismatchException {
SensorContextTester sensorContextTester = SensorContextTester.create(new File(""));
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, sensorContextTester.fileSystem(), mock(ClasspathForMain.class), mock(ClasspathForTest.class), checkFactory);
IncrementalAnalysisSensorContext context = mock(IncrementalAnalysisSensorContext.class);
Configuration config = mock(Configuration.class);
when(context.config()).thenReturn(config);
when(config.getBoolean(any())).thenReturn(Optional.ofNullable(overrideFlagVal));
if (apiResponseVal == null) {
lenient().when(context.canSkipUnchangedFiles()).thenThrow(new NoSuchMethodError("API version mismatch :-("));
} else {
lenient().when(context.canSkipUnchangedFiles()).thenReturn(apiResponseVal);
}
sonarComponents.setSensorContext(context);
if (expectedResult == null) {
ApiMismatchException noSuchMethodError = assertThrows(ApiMismatchException.class, sonarComponents::canSkipUnchangedFiles);
assertThat(noSuchMethodError).hasCause(new NoSuchMethodError("API version mismatch :-("));
} else {
assertThat(sonarComponents.canSkipUnchangedFiles()).isEqualTo(expectedResult);
}
}
use of org.sonar.java.exceptions.ApiMismatchException in project sonar-java by SonarSource.
the class SonarComponentsTest method fileCanBeSkipped_only_logs_on_first_call_input.
private static Stream<Arguments> fileCanBeSkipped_only_logs_on_first_call_input() throws ApiMismatchException {
ApiMismatchException apiMismatchException = new ApiMismatchException(new NoSuchMethodError("API version mismatch :-("));
SonarComponents sonarComponentsThatCanSkipFiles = mock(SonarComponents.class, CALLS_REAL_METHODS);
doReturn(true).when(sonarComponentsThatCanSkipFiles).canSkipUnchangedFiles();
SonarComponents sonarComponentsThatCannotSkipFiles = mock(SonarComponents.class, CALLS_REAL_METHODS);
doReturn(false).when(sonarComponentsThatCannotSkipFiles).canSkipUnchangedFiles();
SonarComponents sonarComponentsWithApiMismatch = mock(SonarComponents.class, CALLS_REAL_METHODS);
doThrow(apiMismatchException).when(sonarComponentsWithApiMismatch).canSkipUnchangedFiles();
InputFile inputFile = mock(InputFile.class);
doReturn(InputFile.Status.SAME).when(inputFile).status();
return Stream.of(Arguments.of(sonarComponentsThatCanSkipFiles, inputFile, LOG_MESSAGE_FILES_CAN_BE_SKIPPED), Arguments.of(sonarComponentsThatCannotSkipFiles, mock(InputFile.class), LOG_MESSAGE_FILES_CANNOT_BE_SKIPPED), Arguments.of(sonarComponentsWithApiMismatch, mock(InputFile.class), LOG_MESSAGE_CANNOT_DETERMINE_IF_FILES_CAN_BE_SKIPPED));
}
Aggregations