testImplementation 'com.tngtech.java:junit-dataprovider'
testImplementation 'commons-io:commons-io'
testImplementation 'junit:junit'
+ testImplementation 'org.junit.jupiter:junit-jupiter-api'
+ testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.assertj:assertj-core'
testImplementation 'com.fasterxml.staxmate:staxmate'
testImplementation 'org.hamcrest:hamcrest-core'
testImplementation 'org.mockito:mockito-core'
+ testImplementation 'org.mockito:mockito-junit-jupiter'
api 'org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures'
testImplementation project(':plugins:sonar-xoo-plugin')
+
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+ testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
license {
}
}
}
+
+test {
+ // Enabling the JUnit Platform (see https://github.com/junit-team/junit5-samples/tree/master/junit5-migration-gradle)
+ useJUnitPlatform()
+}
*/
package org.sonar.scanner;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.time.Clock;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Date;
import javax.annotation.Nullable;
import org.apache.commons.lang.RandomStringUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EmptySource;
+import org.junit.jupiter.params.provider.NullAndEmptySource;
+import org.junit.jupiter.params.provider.NullSource;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.MessageException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
-@RunWith(DataProviderRunner.class)
-public class ProjectInfoTest {
+class ProjectInfoTest {
- private MapSettings settings = new MapSettings();
- private Clock clock = mock(Clock.class);
- private ProjectInfo underTest = new ProjectInfo(settings.asConfig(), clock);
+ private final MapSettings settings = new MapSettings();
+ private final Clock clock = mock(Clock.class);
+ private final ProjectInfo underTest = new ProjectInfo(settings.asConfig(), clock);
@Test
- public void testSimpleDateTime() {
+ void testSimpleDateTime() {
OffsetDateTime date = OffsetDateTime.of(2017, 1, 1, 12, 13, 14, 0, ZoneOffset.ofHours(2));
settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01T12:13:14+0200");
settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
}
@Test
- public void testSimpleDate() {
+ void testSimpleDate() {
LocalDate date = LocalDate.of(2017, 1, 1);
settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
}
@Test
- public void emptyDate() {
+ void emptyDate() {
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "");
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
}
@Test
- public void fail_with_too_long_version() {
+ void fail_with_too_long_version() {
String version = randomAlphabetic(101);
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, version);
}
@Test
- public void fail_with_too_long_buildString() {
+ void fail_with_too_long_buildString() {
String buildString = randomAlphabetic(101);
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, buildString);
"The maximum length is 100 characters.");
}
- @Test
- @UseDataProvider("emptyOrNullString")
- public void getProjectVersion_is_empty_if_property_is_empty_or_null(@Nullable String projectVersion) {
+ @ParameterizedTest
+ @NullAndEmptySource
+ void getProjectVersion_is_empty_if_property_is_empty_or_null(@Nullable String projectVersion) {
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion);
}
@Test
- public void getProjectVersion_contains_value_of_property() {
+ void getProjectVersion_contains_value_of_property() {
String value = RandomStringUtils.randomAlphabetic(10);
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, value);
assertThat(underTest.getProjectVersion()).contains(value);
}
- @Test
- @UseDataProvider("emptyOrNullString")
- public void getBuildString_is_empty_if_property_is_empty_or_null(@Nullable String buildString) {
+ @ParameterizedTest
+ @NullAndEmptySource
+ void getBuildString_is_empty_if_property_is_empty_or_null(@Nullable String buildString) {
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, buildString);
}
@Test
- public void getBuildString_contains_value_of_property() {
+ void getBuildString_contains_value_of_property() {
String value = RandomStringUtils.randomAlphabetic(10);
settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, value);
assertThat(underTest.getBuildString()).contains(value);
}
-
- @DataProvider
- public static Object[][] emptyOrNullString() {
- return new Object[][] {
- {""},
- {null},
- };
- }
}
*/
package org.sonar.scanner.qualitygate;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Answers;
import org.mockito.ArgumentMatcher;
-import org.mockito.Mockito;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.event.Level;
-import org.sonar.api.testfixtures.log.LogTester;
+import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(DataProviderRunner.class)
-public class QualityGateCheckTest {
- private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS);
- private GlobalAnalysisMode analysisMode = mock(GlobalAnalysisMode.class);
- private CeTaskReportDataHolder reportMetadataHolder = mock(CeTaskReportDataHolder.class);
- private ScanProperties properties = mock(ScanProperties.class);
-
- @Rule
- public LogTester logTester = new LogTester();
-
- QualityGateCheck underTest = new QualityGateCheck(wsClient, analysisMode, reportMetadataHolder, properties);
-
- @Before
- public void before() {
+@ExtendWith(MockitoExtension.class)
+class QualityGateCheckTest {
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private DefaultScannerWsClient wsClient;
+ @Mock
+ private GlobalAnalysisMode analysisMode;
+ @Mock
+ private CeTaskReportDataHolder reportMetadataHolder;
+ @Mock
+ private ScanProperties properties;
+
+ @RegisterExtension
+ private final LogTesterJUnit5 logTester = new LogTesterJUnit5();
+
+ private QualityGateCheck underTest;
+
+ @BeforeEach
+ void before() {
+ underTest = new QualityGateCheck(wsClient, analysisMode, reportMetadataHolder, properties);
logTester.setLevel(Level.DEBUG);
- when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
- when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
}
@Test
- public void should_pass_if_quality_gate_ok() {
+ void should_pass_if_quality_gate_ok() {
+ when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
+ when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_wait_and_then_pass_if_quality_gate_ok() {
+ void should_wait_and_then_pass_if_quality_gate_ok() {
+ when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
+ when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(10);
}
@Test
- public void should_fail_if_quality_gate_none() {
+ void should_fail_if_quality_gate_none() {
+ when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
+ when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_fail_if_quality_gate_error() {
+ void should_fail_if_quality_gate_error() {
+ when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
+ when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_wait_and_then_fail_if_quality_gate_error() {
+ void should_wait_and_then_fail_if_quality_gate_error() {
+ when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
+ when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(10);
}
@Test
- public void should_fail_if_quality_gate_timeout_exceeded() {
+ void should_fail_if_quality_gate_timeout_exceeded() {
+ when(reportMetadataHolder.getCeTaskId()).thenReturn("task-1234");
+ when(reportMetadataHolder.getDashboardUrl()).thenReturn("http://dashboard-url.com");
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(1);
}
@Test
- public void should_fail_if_cant_call_ws_for_quality_gate() {
+ void should_fail_if_cant_call_ws_for_quality_gate() {
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_fail_if_invalid_response_from_quality_gate_ws() {
+ void should_fail_if_invalid_response_from_quality_gate_ws() {
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_fail_if_cant_call_ws_for_task() {
+ void should_fail_if_cant_call_ws_for_task() {
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_fail_if_invalid_response_from_ws_task() {
+ void should_fail_if_invalid_response_from_ws_task() {
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
.hasMessage("Failed to parse response from ce-task-url");
}
- @Test
- @UseDataProvider("ceTaskNotSucceededStatuses")
- public void should_fail_if_task_not_succeeded(TaskStatus taskStatus) {
+ @ParameterizedTest
+ @MethodSource("ceTaskNotSucceededStatuses")
+ void should_fail_if_task_not_succeeded(TaskStatus taskStatus) {
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(properties.qualityGateWaitTimeout()).thenReturn(5);
}
@Test
- public void should_skip_wait_if_disabled() {
+ void should_skip_wait_if_disabled() {
when(properties.shouldWaitForQualityGate()).thenReturn(false);
underTest.start();
}
@Test
- public void should_fail_if_enabled_with_medium_test() {
+ void should_fail_if_enabled_with_medium_test() {
when(properties.shouldWaitForQualityGate()).thenReturn(true);
when(analysisMode.isMediumTest()).thenReturn(true);
return qualityGateWsResponse;
}
- @DataProvider
- public static Object[][] ceTaskNotSucceededStatuses() {
- return new Object[][] {
- {TaskStatus.CANCELED},
- {TaskStatus.FAILED},
- };
+ private static Stream<TaskStatus> ceTaskNotSucceededStatuses() {
+ return Stream.of(
+ TaskStatus.CANCELED,
+ TaskStatus.FAILED
+ );
}
private static class WsRequestPathMatcher implements ArgumentMatcher<WsRequest> {
*/
package org.sonar.scanner.scan;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;
+import java.util.stream.Stream;
import javax.annotation.Nullable;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
-import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.config.ScannerProperties;
import org.sonar.core.documentation.DefaultDocumentationLinkGenerator;
import org.sonar.scanner.ProjectInfo;
import static org.mockito.Mockito.when;
import static org.sonar.core.config.ScannerProperties.BRANCHES_DOC_LINK_SUFFIX;
-@RunWith(DataProviderRunner.class)
-public class ProjectReactorValidatorTest {
-
- @Rule
- public LogTester logTester = new LogTester();
+class ProjectReactorValidatorTest {
private final GlobalConfiguration settings = mock(GlobalConfiguration.class);
private final ProjectInfo projectInfo = mock(ProjectInfo.class);
private final ProjectReactorValidator underTest = new ProjectReactorValidator(settings, defaultDocumentationLinkGenerator);
private static final String LINK_TO_DOC = "link_to_documentation";
- @Before
- public void prepare() {
+ @BeforeEach
+ void prepare() {
when(settings.get(anyString())).thenReturn(Optional.empty());
when(defaultDocumentationLinkGenerator.getDocumentationLink(BRANCHES_DOC_LINK_SUFFIX)).thenReturn(LINK_TO_DOC);
}
- @Test
- @UseDataProvider("validKeys")
- public void not_fail_with_valid_key(String validKey) {
+ @ParameterizedTest
+ @MethodSource("validKeys")
+ void not_fail_with_valid_key(String validKey) {
ProjectReactor projectReactor = createProjectReactor(validKey);
underTest.validate(projectReactor);
}
- @DataProvider
- public static Object[][] validKeys() {
- return new Object[][] {
- {"foo"},
- {"123foo"},
- {"foo123"},
- {"1Z3"},
- {"a123"},
- {"123a"},
- {"1:2"},
- {"3-3"},
- {"-:"},
- {"Foobar2"},
- {"foo.bar"},
- {"foo-bar"},
- {"foo:bar"},
- {"foo_bar"}
- };
+ private static Stream<String> validKeys() {
+ return Stream.of(
+ "foo",
+ "123foo",
+ "foo123",
+ "1Z3",
+ "a123",
+ "123a",
+ "1:2",
+ "3-3",
+ "-:",
+ "Foobar2",
+ "foo.bar",
+ "foo-bar",
+ "foo:bar",
+ "foo_bar"
+ );
}
@Test
- public void fail_when_invalid_key() {
+ void fail_when_invalid_key() {
ProjectReactor reactor = createProjectReactor("foo$bar");
assertThatThrownBy(() -> underTest.validate(reactor))
}
@Test
- public void fail_when_only_digits() {
+ void fail_when_only_digits() {
ProjectReactor reactor = createProjectReactor("12345");
assertThatThrownBy(() -> underTest.validate(reactor))
}
@Test
- public void fail_when_backslash_in_key() {
+ void fail_when_backslash_in_key() {
ProjectReactor reactor = createProjectReactor("foo\\bar");
assertThatThrownBy(() -> underTest.validate(reactor))
}
@Test
- public void fail_when_branch_name_is_specified_but_branch_plugin_not_present() {
+ void fail_when_branch_name_is_specified_but_branch_plugin_not_present() {
ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
ProjectReactor reactor = new ProjectReactor(def);
}
@Test
- public void fail_when_pull_request_id_specified_but_branch_plugin_not_present() {
+ void fail_when_pull_request_id_specified_but_branch_plugin_not_present() {
ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
ProjectReactor reactor = new ProjectReactor(def);
}
@Test
- public void fail_when_pull_request_branch_is_specified_but_branch_plugin_not_present() {
+ void fail_when_pull_request_branch_is_specified_but_branch_plugin_not_present() {
ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
ProjectReactor reactor = new ProjectReactor(def);
}
@Test
- public void fail_when_pull_request_base_specified_but_branch_plugin_not_present() {
+ void fail_when_pull_request_base_specified_but_branch_plugin_not_present() {
ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
ProjectReactor reactor = new ProjectReactor(def);
LINK_TO_DOC));
}
- @Test
- @UseDataProvider("validVersions")
- public void not_fail_with_valid_version(@Nullable String validVersion) {
+ @ParameterizedTest
+ @MethodSource("validVersions")
+ void not_fail_with_valid_version(@Nullable String validVersion) {
when(projectInfo.getProjectVersion()).thenReturn(Optional.ofNullable(validVersion));
ProjectReactor projectReactor = createProjectReactor("foo");
underTest.validate(projectReactor);
}
- @DataProvider
- public static Object[][] validVersions() {
- return new Object[][] {
- {null},
- {"1.0"},
- {"2017-10-16"},
- {randomAscii(100)}
- };
+ private static Stream<String> validVersions() {
+ return Stream.of(
+ null,
+ "1.0",
+ "2017-10-16",
+ randomAscii(100)
+ );
}
- @Test
- @UseDataProvider("validBuildStrings")
- public void not_fail_with_valid_buildString(@Nullable String validBuildString) {
+ @ParameterizedTest
+ @MethodSource("validBuildStrings")
+ void not_fail_with_valid_buildString(@Nullable String validBuildString) {
when(projectInfo.getBuildString()).thenReturn(Optional.ofNullable(validBuildString));
ProjectReactor projectReactor = createProjectReactor("foo");
underTest.validate(projectReactor);
}
- @DataProvider
- public static Object[][] validBuildStrings() {
- return new Object[][] {
- {null},
- {"1.0"},
- {"2017-10-16"},
- {randomAscii(100)}
- };
+ private static Stream<String> validBuildStrings() {
+ return Stream.of(
+ null,
+ "1.0",
+ "2017-10-16",
+ randomAscii(100)
+ );
}
private ProjectReactor createProjectReactor(String projectKey, Consumer<ProjectDefinition>... consumers) {
*/
package org.sonar.scanner.scm;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Optional;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Answers;
import org.slf4j.event.Level;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.scm.ScmProvider;
import org.sonar.api.config.Configuration;
import org.sonar.api.notifications.AnalysisWarnings;
+import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.api.utils.MessageException;
-import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.core.config.ScannerProperties;
import org.sonar.scanner.fs.InputModuleHierarchy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.sonar.scanner.scm.ScmConfiguration.MESSAGE_SCM_EXCLUSIONS_IS_DISABLED_BY_CONFIGURATION;
import static org.sonar.scanner.scm.ScmConfiguration.MESSAGE_SCM_STEP_IS_DISABLED_BY_CONFIGURATION;
-@RunWith(DataProviderRunner.class)
-public class ScmConfigurationTest {
+class ScmConfigurationTest {
private final InputModuleHierarchy inputModuleHierarchy = mock(InputModuleHierarchy.class, withSettings().defaultAnswer(Answers.RETURNS_MOCKS));
private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
private final ScmConfiguration underTest;
- @Rule
- public LogTester logTester = new LogTester();
+ @RegisterExtension
+ private final LogTesterJUnit5 logTester = new LogTesterJUnit5();
public ScmConfigurationTest() {
when(scmProvider.key()).thenReturn(scmProviderKey);
}
@Test
- public void do_not_register_warning_when_success_to_autodetect_scm_provider() {
+ void do_not_register_warning_when_success_to_autodetect_scm_provider() {
when(scmProvider.supports(any())).thenReturn(true);
underTest.start();
}
@Test
- public void no_provider_if_no_provider_is_available() {
+ void no_provider_if_no_provider_is_available() {
ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings);
assertThat(underTest.provider()).isNull();
verifyNoInteractions(analysisWarnings);
}
@Test
- public void register_warning_when_fail_to_detect_scm_provider() {
+ void register_warning_when_fail_to_detect_scm_provider() {
underTest.start();
assertThat(underTest.provider()).isNull();
}
@Test
- public void log_when_disabled() {
+ void log_when_disabled() {
logTester.setLevel(Level.DEBUG);
when(settings.getBoolean(CoreProperties.SCM_DISABLED_KEY)).thenReturn(Optional.of(true));
}
@Test
- public void log_when_exclusion_is_disabled() {
+ void log_when_exclusion_is_disabled() {
when(settings.getBoolean(CoreProperties.SCM_EXCLUSIONS_DISABLED_KEY)).thenReturn(Optional.of(true));
underTest.start();
assertThat(logTester.logs()).contains(MESSAGE_SCM_EXCLUSIONS_IS_DISABLED_BY_CONFIGURATION);
}
- @Test
- @UseDataProvider("scmDisabledProperty")
- public void exclusion_is_disabled_by_property(boolean scmDisabled, boolean scmExclusionsDisabled, boolean isScmExclusionDisabled) {
+ @ParameterizedTest
+ @MethodSource("scmDisabledProperty")
+ void exclusion_is_disabled_by_property(boolean scmDisabled, boolean scmExclusionsDisabled, boolean isScmExclusionDisabled) {
when(settings.getBoolean(CoreProperties.SCM_DISABLED_KEY)).thenReturn(Optional.of(scmDisabled));
when(settings.getBoolean(CoreProperties.SCM_EXCLUSIONS_DISABLED_KEY)).thenReturn(Optional.of(scmExclusionsDisabled));
assertThat(underTest.isExclusionDisabled()).isEqualTo(isScmExclusionDisabled);
}
- @DataProvider
- public static Object[][] scmDisabledProperty() {
- return new Object[][] {
- {true, true, true},
- {true, false, true},
- {false, true, true},
- {false, false, false}
- };
+ private static Stream<Arguments> scmDisabledProperty() {
+ return Stream.of(
+ arguments(true, true, true),
+ arguments(true, false, true),
+ arguments(false, true, true),
+ arguments(false, false, false)
+ );
}
@Test
- public void fail_when_multiple_scm_providers_claim_support() {
+ void fail_when_multiple_scm_providers_claim_support() {
when(scmProvider.supports(any())).thenReturn(true);
when(scmProvider.key()).thenReturn("key1", "key2");
}
@Test
- public void fail_when_considerOldScmUrl_finds_invalid_provider_in_link() {
+ void fail_when_considerOldScmUrl_finds_invalid_provider_in_link() {
when(settings.get(ScannerProperties.LINKS_SOURCES_DEV)).thenReturn(Optional.of("scm:invalid"));
assertThatThrownBy(() -> underTest.start())
}
@Test
- public void set_provider_from_valid_link() {
+ void set_provider_from_valid_link() {
when(settings.get(ScannerProperties.LINKS_SOURCES_DEV)).thenReturn(Optional.of("scm:" + scmProviderKey));
underTest.start();
assertThat(underTest.provider()).isSameAs(scmProvider);
}
- @Test
- @UseDataProvider("malformedScmLinks")
- public void dont_set_provider_from_links_if_malformed(String link) {
+ @ParameterizedTest
+ @ValueSource(strings = {"invalid prefix", "scm", "scm:"})
+ void dont_set_provider_from_links_if_malformed(String link) {
when(settings.get(ScannerProperties.LINKS_SOURCES_DEV)).thenReturn(Optional.of(link));
underTest.start();
assertThat(underTest.provider()).isNull();
}
-
- @DataProvider
- public static Object[][] malformedScmLinks() {
- return new Object[][] {
- {"invalid prefix"},
- {"scm"},
- {"scm:"}
- };
- }
}
*/
package org.sonar.scm.git;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.scm.git.strategy.DefaultBlameStrategy.BlameAlgorithmEnum;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(DataProviderRunner.class)
-public class CompositeBlameCommandIT {
+class CompositeBlameCommandIT {
private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
private final ProcessWrapperFactory processWrapperFactory = new ProcessWrapperFactory();
private final NativeGitBlameCommand nativeGitBlameCommand = new NativeGitBlameCommand(System2.INSTANCE, processWrapperFactory);
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ private File temp;
- @Test
- @UseDataProvider("namesOfTheTestRepositoriesWithBlameAlgorithm")
- public void testThatBlameAlgorithmOutputsTheSameDataAsGitNativeBlame(String folder, BlameAlgorithmEnum blameAlgorithm) throws Exception {
+ @ParameterizedTest
+ @MethodSource("namesOfTheTestRepositoriesWithBlameAlgorithm")
+ void testThatBlameAlgorithmOutputsTheSameDataAsGitNativeBlame(String folder, BlameAlgorithmEnum blameAlgorithm) throws Exception {
CompositeBlameCommand underTest = new CompositeBlameCommand(analysisWarnings, new PathResolver(), jGitBlameCommand, nativeGitBlameCommand, (p, f) -> blameAlgorithm);
TestBlameOutput output = new TestBlameOutput();
assertBlameMatchesExpectedBlame(output.blame, gitFolder);
}
- @DataProvider
- public static Object[][] namesOfTheTestRepositoriesWithBlameAlgorithm() {
- List<String> testCases = List.of("one-file-one-commit",
+ private static Stream<Arguments> namesOfTheTestRepositoriesWithBlameAlgorithm() {
+ List<String> testCases = List.of(
+ "one-file-one-commit",
"one-file-two-commits",
"two-files-one-commit",
"merge-commits",
List<BlameAlgorithmEnum> blameStrategies = Arrays.stream(BlameAlgorithmEnum.values()).toList();
return testCases.stream()
- .flatMap(t -> blameStrategies.stream().map(b -> new Object[]{t, b}))
- .toArray(Object[][]::new);
+ .flatMap(t -> blameStrategies.stream().map(b -> arguments(t, b)))
+ .toList().stream();
}
}
private File unzipGitRepository(String repositoryName) throws IOException {
- File gitFolderForEachTest = temp.newFolder().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toFile();
+ File gitFolderForEachTest = temp.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toFile();
Utils.javaUnzip(repositoryName + ".zip", gitFolderForEachTest);
return gitFolderForEachTest.toPath().resolve(repositoryName).toFile();
}