diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-18 14:07:18 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-18 14:07:18 +0200 |
commit | f9f85043a17edeb69f3ea5a93e56b4d60e3a22ae (patch) | |
tree | b0d03b8352f156e560229309601e22103fedde49 /sonar-batch/src/test/java/org | |
parent | 6334cb7d7397e1455099611b3b1259ad050706e6 (diff) | |
download | sonarqube-f9f85043a17edeb69f3ea5a93e56b4d60e3a22ae.tar.gz sonarqube-f9f85043a17edeb69f3ea5a93e56b4d60e3a22ae.zip |
Revert "SONAR-5218 Once a module has been turned into a project, its issues are no more visible in the UI"
This reverts commit 6334cb7d7397e1455099611b3b1259ad050706e6.
Diffstat (limited to 'sonar-batch/src/test/java/org')
4 files changed, 28 insertions, 32 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java index 90721058222..1f557c64ad1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.sonar.api.component.Component; import org.sonar.api.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.resources.Project; import java.util.Arrays; import java.util.List; @@ -36,7 +35,6 @@ public class DefaultIssuableTest { ModuleIssues moduleIssues = mock(ModuleIssues.class); IssueCache cache = mock(IssueCache.class); - Project project = mock(Project.class); Component component = mock(Component.class); @Test @@ -46,7 +44,7 @@ public class DefaultIssuableTest { DefaultIssue unresolved = new DefaultIssue(); when(cache.byComponent("struts:org.apache.Action")).thenReturn(Arrays.asList(resolved, unresolved)); - DefaultIssuable perspective = new DefaultIssuable(component, project, moduleIssues, cache); + DefaultIssuable perspective = new DefaultIssuable(component, moduleIssues, cache); List<Issue> issues = perspective.issues(); assertThat(issues).containsOnly(unresolved); @@ -59,7 +57,7 @@ public class DefaultIssuableTest { DefaultIssue unresolved = new DefaultIssue(); when(cache.byComponent("struts:org.apache.Action")).thenReturn(Arrays.asList(resolved, unresolved)); - DefaultIssuable perspective = new DefaultIssuable(component, project, moduleIssues, cache); + DefaultIssuable perspective = new DefaultIssuable(component, moduleIssues, cache); List<Issue> issues = perspective.resolvedIssues(); assertThat(issues).containsOnly(resolved); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java index 4753023ccbc..d11d0a72111 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java @@ -25,7 +25,6 @@ import org.sonar.api.component.Component; import org.sonar.api.issue.Issuable; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; -import org.sonar.batch.ProjectTree; import org.sonar.core.component.ResourceComponent; import static org.fest.assertions.Assertions.assertThat; @@ -35,11 +34,10 @@ public class IssuableFactoryTest { ModuleIssues moduleIssues = mock(ModuleIssues.class); IssueCache cache = mock(IssueCache.class, Mockito.RETURNS_MOCKS); - ProjectTree projectTree = mock(ProjectTree.class); @Test public void file_should_be_issuable() throws Exception { - IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); + IssuableFactory factory = new IssuableFactory(moduleIssues, cache); Component component = new ResourceComponent(new File("foo/bar.c").setEffectiveKey("foo/bar.c")); Issuable issuable = factory.loadPerspective(Issuable.class, component); @@ -50,7 +48,7 @@ public class IssuableFactoryTest { @Test public void project_should_be_issuable() throws Exception { - IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); + IssuableFactory factory = new IssuableFactory(moduleIssues, cache); Component component = new ResourceComponent(new Project("Foo").setEffectiveKey("foo")); Issuable issuable = factory.loadPerspective(Issuable.class, component); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java index bacfe55be16..3df87485b74 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java @@ -73,7 +73,6 @@ public class ModuleIssuesTest { public void setUp() { when(project.getAnalysisDate()).thenReturn(new Date()); when(project.getEffectiveKey()).thenReturn("org.apache:struts-core"); - when(project.getRoot()).thenReturn(project); } @Test @@ -226,7 +225,6 @@ public class ModuleIssuesTest { assertThat(issue.key()).isNotEmpty(); assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle"); assertThat(issue.componentKey()).isEqualTo("struts:src/org/struts/Action.java"); - assertThat(issue.projectKey()).isEqualTo("org.apache:struts-core"); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java index 8866851b3da..7875ae97f25 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java @@ -19,19 +19,13 @@ */ package org.sonar.batch.issue; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.database.model.Snapshot; import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; -import org.sonar.batch.ProjectTree; import org.sonar.batch.index.SnapshotCache; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.resource.ResourceDao; @@ -40,28 +34,16 @@ import java.util.Collection; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) public class ScanIssueStorageTest extends AbstractDaoTestCase { - - @Mock - SnapshotCache snapshotCache; - - @Mock - ProjectTree projectTree; - - ScanIssueStorage storage; - - @Before - public void setUp() throws Exception { - storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()), projectTree); - } - @Test public void should_load_component_id_from_cache() throws Exception { + SnapshotCache snapshotCache = mock(SnapshotCache.class); when(snapshotCache.get("struts:Action.java")).thenReturn(new Snapshot().setResourceId(123)); + ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis())); long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java")); assertThat(componentId).isEqualTo(123); @@ -70,8 +52,10 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase { @Test public void should_load_component_id_from_db() throws Exception { setupData("should_load_component_id_from_db"); + SnapshotCache snapshotCache = mock(SnapshotCache.class); when(snapshotCache.get("struts:Action.java")).thenReturn(null); + ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis())); long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java")); assertThat(componentId).isEqualTo(123); @@ -80,8 +64,10 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase { @Test public void should_fail_to_load_component_id_if_unknown_component() throws Exception { setupData("should_fail_to_load_component_id_if_unknown_component"); + SnapshotCache snapshotCache = mock(SnapshotCache.class); when(snapshotCache.get("struts:Action.java")).thenReturn(null); + ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis())); try { storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java")); fail(); @@ -92,13 +78,29 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase { @Test public void should_load_project_id() throws Exception { - when(projectTree.getRootProject()).thenReturn((Project) new Project("struts").setId(100)); + SnapshotCache snapshotCache = mock(SnapshotCache.class); + when(snapshotCache.get("struts:Action.java")).thenReturn(new Snapshot().setResourceId(123).setRootProjectId(100)); + ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis())); long projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java")); assertThat(projectId).isEqualTo(100); } + @Test + public void should_fail_to_load_project_id_if_unknown_component() throws Exception { + SnapshotCache snapshotCache = mock(SnapshotCache.class); + when(snapshotCache.get("struts:Action.java")).thenReturn(null); + + ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis())); + try { + storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java")); + fail(); + } catch (Exception e) { + assertThat(e).hasMessage("Project id not found for: struts:Action.java"); + } + } + static class FakeRuleFinder implements RuleFinder { @Override |