Search in sources :

Example 1 with DefaultSensorStorage

use of org.sonar.scanner.sensor.DefaultSensorStorage in project sonarqube by SonarSource.

the class DefaultSymbolizableTest method should_update_cache_when_done.

@Test
public void should_update_cache_when_done() {
    DefaultSensorStorage sensorStorage = mock(DefaultSensorStorage.class);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata(Strings.repeat("azerty\n", 20)).build();
    DefaultSymbolizable symbolPerspective = new DefaultSymbolizable(inputFile, sensorStorage, mock(AnalysisMode.class));
    Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolPerspective.newSymbolTableBuilder();
    Symbol firstSymbol = symbolTableBuilder.newSymbol(4, 8);
    symbolTableBuilder.newReference(firstSymbol, 12);
    symbolTableBuilder.newReference(firstSymbol, 70);
    Symbol otherSymbol = symbolTableBuilder.newSymbol(25, 33);
    symbolTableBuilder.newReference(otherSymbol, 44);
    symbolTableBuilder.newReference(otherSymbol, 60);
    symbolTableBuilder.newReference(otherSymbol, 108);
    Symbolizable.SymbolTable symbolTable = symbolTableBuilder.build();
    symbolPerspective.setSymbolTable(symbolTable);
    ArgumentCaptor<DefaultSymbolTable> argCaptor = ArgumentCaptor.forClass(DefaultSymbolTable.class);
    verify(sensorStorage).store(argCaptor.capture());
    // Map<Symbol, Set<TextRange>>
    assertThat(argCaptor.getValue().getReferencesBySymbol().keySet()).hasSize(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Symbol(org.sonar.api.source.Symbol) DefaultSensorStorage(org.sonar.scanner.sensor.DefaultSensorStorage) AnalysisMode(org.sonar.api.batch.AnalysisMode) DefaultSymbolizable(org.sonar.scanner.source.DefaultSymbolizable) DefaultSymbolTable(org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable) Symbolizable(org.sonar.api.source.Symbolizable) DefaultSymbolizable(org.sonar.scanner.source.DefaultSymbolizable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 AnalysisMode (org.sonar.api.batch.AnalysisMode)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 DefaultSymbolTable (org.sonar.api.batch.sensor.symbol.internal.DefaultSymbolTable)1 Symbol (org.sonar.api.source.Symbol)1 Symbolizable (org.sonar.api.source.Symbolizable)1 DefaultSensorStorage (org.sonar.scanner.sensor.DefaultSensorStorage)1 DefaultSymbolizable (org.sonar.scanner.source.DefaultSymbolizable)1