Search in sources :

Example 1 with FileAttributes

use of org.sonar.ce.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class CommonRuleEngineImplTest method do_not_process_files_with_unknown_language.

@Test
public void do_not_process_files_with_unknown_language() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, null, 1)).build();
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).isEmpty();
    verifyZeroInteractions(rule1, rule2);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 2 with FileAttributes

use of org.sonar.ce.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class CommonRuleEngineImplTest method process_files_with_known_language.

@Test
public void process_files_with_known_language() {
    ReportComponent file = ReportComponent.builder(Component.Type.FILE, 1).setKey("FILE_KEY").setUuid("FILE_UUID").setFileAttributes(new FileAttributes(false, "java", 1)).build();
    DefaultIssue issue = new DefaultIssue();
    when(rule1.processFile(file, "java")).thenReturn(issue);
    when(rule2.processFile(file, "java")).thenReturn(null);
    Collection<DefaultIssue> issues = underTest.process(file);
    assertThat(issues).containsOnly(issue);
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 3 with FileAttributes

use of org.sonar.ce.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class SourceLineReadersFactoryTest method initBasicReport.

private void initBasicReport(int numberOfLines) {
    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren(ReportComponent.builder(Component.Type.FILE, FILE1_REF).setUuid(FILE1_UUID).setKey("MODULE_KEY:src/Foo.java").setFileAttributes(new FileAttributes(false, null, numberOfLines)).build()).build()).build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(1).setType(ScannerReport.Component.ComponentType.PROJECT).addChildRef(2).build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(2).setType(ScannerReport.Component.ComponentType.MODULE).addChildRef(FILE1_REF).build());
    reportReader.putComponent(ScannerReport.Component.newBuilder().setRef(FILE1_REF).setType(ScannerReport.Component.ComponentType.FILE).setLines(numberOfLines).build());
}
Also used : FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes)

Example 4 with FileAttributes

use of org.sonar.ce.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class NewMaintainabilityMeasuresVisitorTest method compute_new_maintainability_rating_to_A_when_no_debt.

@Test
public void compute_new_maintainability_rating_to_A_when_no_debt() {
    when(newLinesRepository.newLinesAvailable()).thenReturn(true);
    when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST);
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(builder(DIRECTORY, 111).addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()).build()).build());
    underTest.visit(treeRootHolder.getRoot());
    assertNewMaintainability(LANGUAGE_1_FILE_REF, A);
    assertNewMaintainability(111, A);
    assertNewMaintainability(ROOT_REF, A);
}
Also used : FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Example 5 with FileAttributes

use of org.sonar.ce.task.projectanalysis.component.FileAttributes in project sonarqube by SonarSource.

the class NewMaintainabilityMeasuresVisitorTest method file_has_0_new_debt_ratio_if_no_line_is_new.

@Test
public void file_has_0_new_debt_ratio_if_no_line_is_new() {
    ReportComponent file = builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build();
    treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).addChildren(file).build());
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50));
    measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
    setNewLines(file);
    underTest.visit(treeRootHolder.getRoot());
    assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0);
    assertNewDebtRatioValues(ROOT_REF, 0);
}
Also used : ReportComponent(org.sonar.ce.task.projectanalysis.component.ReportComponent) FileAttributes(org.sonar.ce.task.projectanalysis.component.FileAttributes) Test(org.junit.Test)

Aggregations

FileAttributes (org.sonar.ce.task.projectanalysis.component.FileAttributes)20 Test (org.junit.Test)17 ReportComponent (org.sonar.ce.task.projectanalysis.component.ReportComponent)12 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)8 Component (org.sonar.ce.task.projectanalysis.component.Component)6 ComponentDto (org.sonar.db.component.ComponentDto)5 Measure (org.sonar.ce.task.projectanalysis.measure.Measure)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Block (org.sonar.duplications.block.Block)1 ByteArray (org.sonar.duplications.block.ByteArray)1