@Test
 public void should_execute_on_java_project() {
   Project project = mock(Project.class);
   when(project.getLanguageKey()).thenReturn("java");
   assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
   when(project.getLanguageKey()).thenReturn("py");
   assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
 }
  @Test
  public void testShouldExecuteOnProject() throws Exception {
    Configuration conf = new BaseConfiguration();
    GendarmeSensor sensor =
        new GendarmeSensor.RegularGendarmeSensor(
            null,
            rulesProfile,
            profileExporter,
            null,
            new CSharpConfiguration(conf),
            microsoftWindowsEnvironment);

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project #1");
    when(project.getLanguageKey()).thenReturn("cs");
    assertTrue(sensor.shouldExecuteOnProject(project));

    conf.addProperty(GendarmeConstants.MODE, AbstractRegularCSharpSensor.MODE_SKIP);
    sensor =
        new GendarmeSensor.RegularGendarmeSensor(
            null,
            rulesProfile,
            profileExporter,
            null,
            new CSharpConfiguration(conf),
            microsoftWindowsEnvironment);
    assertFalse(sensor.shouldExecuteOnProject(project));
  }
  @Test
  public void testShouldNotExecuteOnTestProject() throws Exception {

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project Test");
    when(project.getLanguageKey()).thenReturn("cs");
    assertFalse(sensor.shouldExecuteOnProject(project));
  }
 /** {@inheritDoc} */
 public boolean shouldExecuteOnProject(Project project) {
   if (project.isRoot() || !CSharpConstants.LANGUAGE_KEY.equals(project.getLanguageKey())) {
     return false;
   }
   boolean skipMode = AbstractCSharpSensor.MODE_SKIP.equalsIgnoreCase(executionMode);
   boolean isTestProject =
       microsoftWindowsEnvironment.getCurrentProject(project.getName()).isTest();
   return !isTestProject && !skipMode;
 }
  @Test
  public void testShouldNotExecuteOnTestProjectOnReuseMode() throws Exception {

    conf.setProperty(GendarmeConstants.MODE, GendarmeSensor.MODE_REUSE_REPORT);

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project Test");
    when(project.getLanguageKey()).thenReturn("cs");
    assertFalse(sensor.shouldExecuteOnProject(project));
  }
  @Test
  public void testShouldSkipProject() throws Exception {

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project #1");
    when(project.getLanguageKey()).thenReturn("cs");
    conf.addProperty(GendarmeConstants.MODE, GendarmeSensor.MODE_SKIP);
    initializeSensor();
    assertFalse(sensor.shouldExecuteOnProject(project));
  }
  @Test
  public void testShouldNotExecuteOnProjectUsingPatterns() throws Exception {

    conf.setProperty(GendarmeConstants.ASSEMBLIES_TO_SCAN_KEY, new String[] {"**/*.whatever"});
    conf.setProperty(
        CSharpConstants.BUILD_CONFIGURATION_KEY,
        "DummyBuildConf"); // we simulate no generated assemblies

    when(solution.getSolutionDir()).thenReturn(TestUtils.getResource("/Sensor"));
    when(vsProject.getDirectory()).thenReturn(TestUtils.getResource("/Sensor"));

    Project project = mock(Project.class);
    when(project.getName()).thenReturn("Project #1");
    when(project.getLanguageKey()).thenReturn("cs");

    assertFalse(sensor.shouldExecuteOnProject(project));
  }
  @Before
  public void init() {
    vsProject1 = mock(VisualStudioProject.class);
    when(vsProject1.getName()).thenReturn("Project #1");
    vsTestProject2 = mock(VisualStudioProject.class);
    when(vsTestProject2.getName()).thenReturn("Project Test #2");
    when(vsTestProject2.isTest()).thenReturn(true);
    solution = mock(VisualStudioSolution.class);
    when(solution.getProjects()).thenReturn(Lists.newArrayList(vsProject1, vsTestProject2));
    when(solution.getTestProjects()).thenReturn(Lists.newArrayList(vsTestProject2));

    microsoftWindowsEnvironment = new MicrosoftWindowsEnvironment();
    microsoftWindowsEnvironment.setCurrentSolution(solution);

    project = mock(Project.class);
    when(project.getLanguageKey()).thenReturn("cs");
    when(project.getName()).thenReturn("Project #1");
  }
  @Before
  public void init() {
    project = mock(Project.class);
    ProjectFileSystem pfs = mock(ProjectFileSystem.class);

    // Don't pollute current working directory
    when(pfs.getSonarWorkingDirectory()).thenReturn(new File("target"));

    File baseDir = DelphiUtils.getResource(ROOT_NAME);

    when(project.getLanguage()).thenReturn(DelphiLanguage.instance);
    when(project.getFileSystem()).thenReturn(pfs);
    when(project.getLanguageKey()).thenReturn(DelphiLanguage.KEY);

    when(pfs.getBasedir()).thenReturn(baseDir);

    File srcFile = DelphiUtils.getResource(TEST_FILE);
    List<File> sourceFiles = new ArrayList<File>();
    sourceFiles.add(srcFile);

    when(pfs.getSourceFiles(DelphiLanguage.instance)).thenReturn(sourceFiles);

    sensor = new DelphiPmdSensor(new DebugRuleFinder());
  }
 private static Project mockProjectWithLanguageKey(String languageKey) {
   Project project = TestUtils.mockProject();
   when(project.getLanguageKey()).thenReturn(languageKey);
   return project;
 }
Beispiel #11
0
 public boolean shouldExecuteOnProject(Project project) {
   return CxxLanguage.KEY.equals(project.getLanguageKey());
 }
  @Test
  public void shouldNotExecuteOnProject() {
    when(project.getLanguageKey()).thenReturn(Java.KEY);

    assertThat(sensor.shouldExecuteOnProject(project), is(false));
  }
  @Test
  public void shouldExecuteOnProject() {
    when(project.getLanguageKey()).thenReturn(Flex.KEY);

    assertThat(sensor.shouldExecuteOnProject(project), is(true));
  }
Beispiel #14
0
 /** {@inheritDoc} */
 public boolean shouldExecuteOnProject(Project project) {
   return PhpConstants.LANGUAGE_KEY.equals(project.getLanguageKey())
       && configuration.isDynamicAnalysisEnabled()
       && !configuration.isSkip()
       && !project.getFileSystem().testFiles(PhpConstants.LANGUAGE_KEY).isEmpty();
 }
 /** {@inheritDoc} */
 public boolean shouldExecuteOnProject(Project project) {
   return project.getLanguageKey().equals(Java.KEY) && configuration.isActive();
 }