Search in sources :

Example 66 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultCpdTokensTest method validate_tokens_order.

@Test
public void validate_tokens_order() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 6, 1, 10), "bar");
    try {
        tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Tokens of file [moduleKey=foo, relative=src/Foo.java, basedir=foo] should be provided in order.\n" + "Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]]\n" + "Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]");
    }
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 67 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultCpdTokensTest method save_one_token.

@Test
public void save_one_token() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
    tokens.save();
    verify(sensorStorage).store(tokens);
    assertThat(tokens.getTokenLines()).extracting("value", "startLine", "hashCode", "startUnit", "endUnit").containsExactly(tuple("foo", 1, "foo".hashCode(), 1, 1));
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 68 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class DefaultCpdTokensTest method basic_validation.

@Test
public void basic_validation() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage);
    try {
        tokens.save();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Call onFile() first");
    }
    try {
        tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Call onFile() first");
    }
    try {
        tokens.addToken(null, "foo");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Range should not be null");
    }
    try {
        tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Image should not be null");
    }
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 69 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class SensorContextTesterTest method testSettings.

@Test
public void testSettings() {
    Settings settings = new MapSettings();
    settings.setProperty("foo", "bar");
    tester.setSettings(settings);
    assertThat(tester.settings().getString("foo")).isEqualTo("bar");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 70 with MapSettings

use of org.sonar.api.config.MapSettings in project sonarqube by SonarSource.

the class FileExclusionsTest method load_inclusions.

@Test
public void load_inclusions() {
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "**/*Foo.java");
    settings.setProperty(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY, "**/*FooTest.java");
    FileExclusions moduleExclusions = new FileExclusions(settings);
    assertThat(moduleExclusions.sourceInclusions()).containsOnly("**/*Foo.java");
    assertThat(moduleExclusions.testInclusions()).containsOnly("**/*FooTest.java");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Aggregations

MapSettings (org.sonar.api.config.MapSettings)98 Test (org.junit.Test)75 Settings (org.sonar.api.config.Settings)36 Before (org.junit.Before)20 URI (java.net.URI)13 Languages (org.sonar.api.resources.Languages)9 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)9 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)8 File (java.io.File)7 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)7 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)6 Properties (java.util.Properties)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)5 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)5 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 InputFile (org.sonar.api.batch.fs.InputFile)4 InputStream (java.io.InputStream)3 Description (org.hamcrest.Description)3 CoreProperties (org.sonar.api.CoreProperties)3