From 3ac6697df2bc10a1f01f31fcc8dad3154a8d2a2e Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 3 Jun 2011 18:37:00 +0400 Subject: [PATCH] SONAR-553 Execute ProjectLinksSensor only for latest analysis --- .../core/sensors/ProjectLinksSensor.java | 2 +- .../core/sensors/ProjectLinksSensorTest.java | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java index 5f0ace5847f..be80f88bd33 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java @@ -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) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java index d4a6b85a72d..6baeb031c47 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java @@ -19,6 +19,11 @@ */ 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); -- 2.39.5