Search in sources :

Example 1 with ModuleSensorExtensionDictionary

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

the class ModuleSensorExtensionDictionaryTest method methodDependsUponCollection.

@Test
public void methodDependsUponCollection() {
    Object a = new GeneratesSomething("foo");
    Object b = new MethodDependentOf(Arrays.asList("foo"));
    ModuleSensorExtensionDictionary selector = newSelector(Marker.class, a, b);
    List<Object> extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(2);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
    // different initial order
    selector = newSelector(Marker.class, b, a);
    extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(2);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
}
Also used : ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ModuleSensorExtensionDictionary

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

the class ModuleSensorExtensionDictionaryTest method useClassAnnotationsOnInterfaces.

@Test
public void useClassAnnotationsOnInterfaces() {
    Object a = new InterfaceDependedUpon() {
    };
    Object b = new InterfaceDependsUpon() {
    };
    ModuleSensorExtensionDictionary selector = newSelector(Marker.class, a, b);
    List<Object> extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(2);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
    // different initial order
    selector = newSelector(Marker.class, b, a);
    extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(2);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
}
Also used : ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ModuleSensorExtensionDictionary

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

the class ModuleSensorExtensionDictionaryTest method dependsUponInheritedPhase.

@Test
public void dependsUponInheritedPhase() {
    PreSensorSubclass pre = new PreSensorSubclass();
    NormalSensor normal = new NormalSensor();
    PostSensorSubclass post = new PostSensorSubclass();
    ModuleSensorExtensionDictionary selector = newSelector(Sensor.class, normal, post, pre);
    List extensions = new ArrayList<>(selector.select(Sensor.class, true, null));
    assertThat(extensions).containsExactly(pre, normal, post);
}
Also used : ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Sensor(org.sonar.api.batch.sensor.Sensor) Test(org.junit.Test)

Example 4 with ModuleSensorExtensionDictionary

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

the class ModuleSensorExtensionDictionaryTest method inheritAnnotations.

@Test
public void inheritAnnotations() {
    Object a = new SubClass("foo");
    Object b = new MethodDependentOf("foo");
    ModuleSensorExtensionDictionary selector = newSelector(Marker.class, b, a);
    List<Object> extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(2);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
    // change initial order
    selector = newSelector(Marker.class, a, b);
    extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(2);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
}
Also used : ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with ModuleSensorExtensionDictionary

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

the class ModuleSensorExtensionDictionaryTest method sortExtensionsByDependency.

@Test
public void sortExtensionsByDependency() {
    Object a = new MethodDependentOf(null);
    Object b = new MethodDependentOf(a);
    Object c = new MethodDependentOf(b);
    ModuleSensorExtensionDictionary selector = newSelector(Marker.class, b, c, a);
    List<Object> extensions = new ArrayList<>(selector.select(Marker.class, true, null));
    assertThat(extensions).hasSize(3);
    assertThat(extensions.get(0)).isEqualTo(a);
    assertThat(extensions.get(1)).isEqualTo(b);
    assertThat(extensions.get(2)).isEqualTo(c);
}
Also used : ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ModuleSensorExtensionDictionary (org.sonar.scanner.sensor.ModuleSensorExtensionDictionary)17 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)8 Sensor (org.sonar.api.batch.sensor.Sensor)6 ExtensionContainer (org.sonar.core.platform.ExtensionContainer)3 ModuleSensorContext (org.sonar.scanner.sensor.ModuleSensorContext)3 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)2 ModuleSensorWrapper (org.sonar.scanner.sensor.ModuleSensorWrapper)2 ModuleSensorsExecutor (org.sonar.scanner.sensor.ModuleSensorsExecutor)2 List (java.util.List)1 Before (org.junit.Before)1 ModuleSensorOptimizer (org.sonar.scanner.sensor.ModuleSensorOptimizer)1