new SurefireSensor().collect(project, mock(SensorContext.class), new File("unknown"));
}
-
private SensorContext mockContext() {
SensorContext context = mock(SensorContext.class);
when(context.isIndexed(any(Resource.class), eq(false))).thenReturn(true);
@Test
public void shouldHandleTestSuiteDetails() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/shouldHandleTestSuiteDetails/").toURI()));
// 3 classes, 6 measures by class
- verify(context, times(3)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(3)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
eq(CoreMetrics.SKIPPED_TESTS), anyDouble());
- verify(context, times(3)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(3)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
eq(CoreMetrics.TESTS), anyDouble());
- verify(context, times(18)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(18)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
(Metric) anyObject(), anyDouble());
- verify(context, times(3)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(3)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
argThat(new IsMeasure(CoreMetrics.TEST_DATA)));
verify(context).saveMeasure(eq(new JavaFile("org.sonar.core.ExtensionsFinderTest", true)), eq(CoreMetrics.TESTS), eq(4d));
@Test
public void shouldSaveErrorsAndFailuresInXML() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/shouldSaveErrorsAndFailuresInXML/").toURI()));
// 1 classes, 6 measures by class
- verify(context, times(1)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(1)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
eq(CoreMetrics.SKIPPED_TESTS), anyDouble());
- verify(context, times(1)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(1)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
eq(CoreMetrics.TESTS), anyDouble());
- verify(context, times(6)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(6)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
(Metric) anyObject(), anyDouble());
- verify(context, times(1)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+ verify(context, times(1)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
argThat(new IsMeasure(CoreMetrics.TEST_DATA)));
verify(context).saveMeasure(eq(new JavaFile("org.sonar.core.ExtensionsFinderTest", true)),
@Test
public void shouldManageClassesWithDefaultPackage() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/shouldManageClassesWithDefaultPackage/").toURI()));
verify(context).saveMeasure(new JavaFile("NoPackagesTest", true), CoreMetrics.TESTS, 2d);
@Test
public void successRatioIsZeroWhenAllTestsFail() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/successRatioIsZeroWhenAllTestsFail/").toURI()));
verify(context).saveMeasure(eq(new JavaFile("org.sonar.Foo", true)), eq(CoreMetrics.TESTS), eq(2d));
@Test
public void measuresShouldNotIncludeSkippedTests() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/measuresShouldNotIncludeSkippedTests/").toURI()));
verify(context).saveMeasure(eq(new JavaFile("org.sonar.Foo", true)), eq(CoreMetrics.TESTS), eq(2d));
@Test
public void noSuccessRatioIfNoTests() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/noSuccessRatioIfNoTests/").toURI()));
verify(context).saveMeasure(eq(new JavaFile("org.sonar.Foo", true)), eq(CoreMetrics.TESTS), eq(0d));
@Test
public void ignoreSuiteAsInnerClass() throws URISyntaxException {
SensorContext context = mockContext();
- new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+ new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
"/org/sonar/plugins/surefire/SurefireSensorTest/ignoreSuiteAsInnerClass/").toURI()));
// ignore TestHandler$Input.xml
}
};
}
-
- private static Project newJarProject() {
- return new Project("key").setPackaging("jar");
- }
-
- private static Project newPomProject() {
- return new Project("key").setPackaging("pom");
- }
}