]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-553 Execute ProjectLinksSensor only for latest analysis
authorEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 3 Jun 2011 14:37:00 +0000 (18:37 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 3 Jun 2011 15:23:07 +0000 (19:23 +0400)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java

index 5f0ace5847f32ec3f3821c8ef17e79111fa88a2f..be80f88bd33c7dc31de25a4bf3efbc83eab18390 100644 (file)
@@ -46,7 +46,7 @@ public class ProjectLinksSensor implements Sensor {
   }
 
   public boolean shouldExecuteOnProject(Project project) {
-    return true;
+    return project.isLatestAnalysis();
   }
 
   public void analyse(Project project, SensorContext context) {
index d4a6b85a72daf916dfc31d89be9901147a485f5a..6baeb031c471a57160c6994f9223d583c71e5c3b 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.*;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.project.MavenProject;
 import org.hamcrest.BaseMatcher;
@@ -29,12 +34,19 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.resources.ProjectLink;
 import org.sonar.api.test.MavenTestUtils;
 
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
 public class ProjectLinksSensorTest {
 
+  @Test
+  public void shouldExecuteOnlyForLatestAnalysis() {
+    MavenProject pom = mock(MavenProject.class);
+    Project project = mock(Project.class);
+    when(project.isLatestAnalysis()).thenReturn(true).thenReturn(false);
+    assertThat(new ProjectLinksSensor(pom).shouldExecuteOnProject(project), is(true));
+    assertThat(new ProjectLinksSensor(pom).shouldExecuteOnProject(project), is(false));
+    verify(project, times(2)).isLatestAnalysis();
+    verifyNoMoreInteractions(project);
+  }
+
   @Test
   public void shouldSaveLinks() {
     SensorContext context = mock(SensorContext.class);